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

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
 
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.
 
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?
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
Back
Top