Solved Is there a program that detects modem once it's turned on?

Leveret

Member

Reaction score: 6
Messages: 60

If I only turn on my DSL modem after logging in, it will not connect. It will if I turn it on before logging in. Is there a program that can detect when the modem is turned on and can help it connect? I'm thinking of something that monitors
 

aragats

Daemon

Reaction score: 499
Messages: 1,213

You didn't provide enough information on your setup.
Is the modem directly connected to your computer?
What does it mean «can help it connect»? This contradicts your phrase «It will [connect] if I turn it on before logging in»
Do you need to run a program to connect? Usually DSL modems are stand-alone devices which don't require any configuration every time you turn them on.

With direct connection you can run a script to check the interface's status ("no carrier"), otherwise you can ping either modem's LAN interface or an external server.
 

roccobaroccoSC

Well-Known Member

Reaction score: 95
Messages: 423

It's obviously a command in your login scripts that detects the modem. Browse into the source of the login scripts of your shell and you'll probably find what it does to detect the modem.
Maybe it probes it and sets an environment variable?
 
OP
OP
L

Leveret

Member

Reaction score: 6
Messages: 60

The modem is connected to a linksys switch box. The problem is that if I log into my desktop, kde5, without the modem being on, it won't connect to the Internet if I decide to turn it on. I'm still somewhat new to BSD and I wouldn't know about environment variables set by the login script. My rc.conf uses the configuration created by the installation program. I noticed that if the modem was on during boot I can turn it off and back on again and it will connect.
 
OP
OP
L

Leveret

Member

Reaction score: 6
Messages: 60

My rc.conf:
Code:
hostname="myserver.host.com"
zfs_enable="YES"
powerd_enable="NO"
powerdxx_enable="YES"
powerdxx_flags="-n adaptive -a hiadaptive -b adaptive -m 800 -M 1600"
rc_fast="YES"
rc_info="NO"
rc_startmsgs="NO"
devfs_system_ruleset="system"
autoboot="YES"
background_dhclient="YES"
defaultroute_delay="0"
ifconfig_re0="DHCP"
ifconfig_re0_ipv6="inet6 accept_rtadv"
sshd_enable="YES"
moused_enable="YES"
ntpd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="NO"
firewall_enable="YES"
firewall_type="workstation"
firewall_logging="YES"
firewall_quiet="YES"
cupsd_enable="YES"
dbus_enable="YES"
hald_enable="YES"
sddm_enable="YES"
I don't have a /usr/local/etc/rc.conf.
 

aragats

Daemon

Reaction score: 499
Messages: 1,213

I think the problem is the DHCP setting:
Code:
ifconfig_re0="DHCP"
When you power up your computer with the modem turned off, the init scripts try to configure the network by sending DHCP requests: the physical connection is detected since you have a switch in between, but there no response from your modem, and the network remains unconfigured.
The easiest way to fix it will be assigning a static address to your re0 interface. To be on the safe side you can either reserve it in your modem (if it allows that), or chose one outside of the range dedicated for dynamic addresses. In your /etc/rc.conf replace ifconfig_re0="DHCP" with:
Code:
ifconfig_re0="inet 192.168.0.25 netmask 255.255.255.0"
defaultrouter="192.168.0.1"
Of course, check the actual range first (the above is just an example) – when your network is configured automatically by running ifconfig re0 and netstat -rn.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 7,372
Messages: 29,915

You might want to change your DHCP lease-time in your modem if that's possible. Although during powerup the interface doesn't get an IP address, dhclient(8) still runs in the background and will periodically send out DHCP DISCOVER messages. As soon as the modem is online and the DHCP service starts responding dhclient(8) will automatically get an IP address.

It also keeps the previously assigned IP address around, in case the DHCP service isn't available:
Code:
     Old leases are kept around in case the DHCP server is unavailable when
     dhclient is first invoked (generally during the initial system boot
     process).  In that event, old leases from the dhclient.leases.IFNAME file
     which have not yet expired are tested, and if they are determined to be
     valid, they are used until either they expire or the DHCP server becomes
     available.

     A mobile host which may sometimes need to access a network on which no
     DHCP server exists may be preloaded with a lease for a fixed address on
     that network.  When all attempts to contact a DHCP server have failed,
     dhclient will try to validate the static lease, and if it succeeds, it
     will use that lease until it is restarted.
So, all you need to do is wait. Or force a refresh with service dhclient restart re0.

I'm still somewhat new to BSD and I wouldn't know about environment variables set by the login script.
Your login actually has nothing to do with it.
 
OP
OP
L

Leveret

Member

Reaction score: 6
Messages: 60

Finally figured out the problem with connecting to the Internet is with the switch box, LinkSys1500, that my modem was plugged into. I have no problems using DHCP, even if the modem was only turned on after booting and logging in, if the modem is plugged directly into the motherboard's Ethernet connector. I have a Gigabyte motherboard. Not sure if there is a conflict with LinkSys. Don't know if anyone can shed light on Gigabyte boards and LinkSys switch boxes. Either way I'll consider this solved.
 

aragats

Daemon

Reaction score: 499
Messages: 1,213

I have no problems using DHCP ... if the modem is plugged directly into the motherboard's Ethernet connector. ... Not sure if there is a conflict with LinkSys.
There is no magic, I already explained above: when you have your switch connected to the PC, the OS detects physical connection and tries to get an IP address by sending DHCP requests. After timeout it doesn't try anymore since the status of physical connection doesn't change. When your modem is connected to the PC and it's off, there is no actual physical connection (no carrier), the DHCP client doesn't even try sending anything out. When the modem is up, the OS detects carrier and starts DHCP communication.
 
OP
OP
L

Leveret

Member

Reaction score: 6
Messages: 60

I tried to assign a static address using the following info but kept getting error messages:
Code:
$ ifconfig:

re0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=8209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC,LINKSTATE>
        ether e0:d5:5e:d0:b9:c2
        inet6 fe80::e2d5:5eff:fed0:b9c2%re0 prefixlen 64 scopeid 0x1 
        inet 192.168.1.47 netmask 0xffffff00 broadcast 255.255.255.255 
        media: Ethernet autoselect (100baseTX <full-duplex>)
        status: active
        nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
        inet6 ::1 prefixlen 128 
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 
        inet 127.0.0.1 netmask 0xff000000 
        groups: lo 
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
$ netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags     Netif Expire
default            192.168.1.1        UGS         re0
127.0.0.1          link#2             UH          lo0
192.168.1.0/24     link#1             U           re0
192.168.1.47       link#1             UHS         lo0

Internet6:
Destination                       Gateway                       Flags     Netif Expire
::/96                             ::1                           UGRS        lo0
::1                               link#2                        UH          lo0
::ffff:0.0.0.0/96                 ::1                           UGRS        lo0
fe80::/10                         ::1                           UGRS        lo0
fe80::%re0/64                     link#1                        U           re0
fe80::e2d5:5eff:fed0:b9c2%re0     link#1                        UHS         lo0
fe80::%lo0/64                     link#2                        U           lo0
fe80::1%lo0                       link#2                        UHS         lo0
ff02::/16                         ::1                           UGRS        lo0
[code]
In my [file]rc.conf[/file] I had:
[code]
ifconfig_re0="inet 192.168.1.47 netmask 255.255.255.0"
defaultrouter="192.168.1.1"
The DHCP entries were commented out. The modem was plugged into the switch box. An ethernet cable was plugged from it into my computer. The error said the entries in the first line don't exist. What did I do wrong?
 
Last edited by a moderator:
OP
OP
L

Leveret

Member

Reaction score: 6
Messages: 60

I knew I was doing something wrong because of the error messages I got but I didn't want to give up on this. I changed the netmask to 0xffffff00 and I have static addressing working. I can now connect without fail. Thanks to aragats and sirdice for their advice and support.
 
Top