ADSL connection

I have always used BT for my broadband connection and I have no real plans to change it. Although I am quite a long way from the exchange I still regularily achieve 7 MBit/s download speeds so I am happy.

To interface to the ADSL connection I use a D-Link DSL-300T modem. As this is on the "red" side of the firewall there is no need for router/switching/NAT or wireless functionality so I went for the simplest box available. The network interface connected to the modem uses DHCP to fetch the real, BT provided, IP address from the modem and allocate it to this network port.

The firewall uses IPtables to do the packet filtering and provide the NAT functionality.

Since I installed Opensuse 11.0 I have a problem with DHCP renewing the IP lease with the modem. The modem was originally configured to only give a lease length of 180 secs which caused the lease to be renewed every 90 secs. This was causing major problems with Opensuse 11.0 so I extended the lease to 1 day. This caused a problem as the server IP address would be out of step with the BT issued address if the ADSL connection was restarted by the modem (which happens quite often for me). To overcome this problem the server now runs a cron job to check the IP address.

The crontab entry is

*/5 * * * *     root  /usr/local/net_test/net_test

and net_test is

#!/usr/bin/perl
# this script must be run from cron
# defines
 use warnings;
 use Sys::Syslog qw( :DEFAULT setlogsock);

# ping1 and ping2 are IP address that you know will respond to the ping
# I use my web hosting IP for both these addresses
 $ping1   = "xxx.xxx.xxx.xxx";

 $ping2   = "xxx.xxx.xxx.xxx";

# change admin to the email name at the server where you want the messages to be sent
 $admin   = "admin";

# change eth0 to the interface connected to the modem
 $netdev  = "eth0";

 $msgbody = "I think the network is down!";

 $msgsub  = "Network Down!";

sub pingtest($$) {
  my ($ping) = @_;
  system(sprintf("ping -q -I %s -c 1 %s>/dev/null", $netdev, $ping));
  $retcode = $? >> 8;
  # ping returns 1 if unable to connect
  return $retcode;

 }

$test1 = &pingtest($ping1);

if ($test1 eq "1") {
  $test2 = &pingtest($ping2);
  if ($test2 eq "1") {
    print("Shutting down $netdev...\n");
    system(sprintf("ifdown %s", $netdev));
    print("Bringing up $netdev...\n");
    system(sprintf("ifup %s", $netdev));
# log reset event
    setlogsock('unix');
    openlog($0,'','user');
    syslog('err', 'Network port $netdev reset');
    closelog;
    $rtest1 = &pingtest($ping1);
    if ($rtest1 eq "1") {
      $rtest2 = &pingtest($ping2);
      if ($rtest2 eq "1") {
# send mail if network won't come back
        system(sprintf("echo \"%s\"|/bin/mail -s \"%s\" %s", $msgbody,$msgsub, $admin));
        exit(1);
      }
    }
  }
 }
exit(0);

The code above is not my own work and the original came from http://techrepublic.com.com/html/tr/sidebars/5032650-0.html

 


 

As I am operating my own mail and web servers I need to manage the problem of the dynamically allocated IP address and mapping to my domain name.

The first part of the solution is to place the following script in /etc/sysconfig/network/if-up.d

#!/bin/bash
#
numArgs=$#
#
callingname="$0"
#
configname="$1"
shift
interface="$1"
shift
# And shift away the '-o'.
shift
options="$@"
#
function log_warn()
{
        /bin/logger -t $0 -p daemon.warn "$1"
}
#
        log_warn " $numArgs  0=$callingname  1=$configname  2=$interface   3=$options"
#
# Include all the variables from DHCP file in routine
#
        HostInfoFilePath="/var/lib/dhcpcd/dhcpcd-$interface.info"
        . "$HostInfoFilePath"

        log_warn "IP Address for interface $interface = $IPADDR"

case "$IPADDR" in
10.*)           ;;
172.1[6-9].* | 172.2[0-9].* | 172.3[0-1].*)     ;;
192.168.*)      ;;
"")             echo Local IP address
                ;;
*)              (
#               sleep 5
                /usr/local/ddns/dyndns.pl $IPADDR
                ) &
                ;;
esac

This script extracts the new IP address from the if-up call and passes it to the script that updates the information at the dynamic dns operator. I have used everydns for a number of years and they have proved very reliable.