Wednesday, January 23, 2008

ADSL Connections on Linux

It seems this is a very commonly faced problem and the solution is not very clearly stated anywhere. This is an attempt to bridge the gap. It should work at least for people in India using the Dataone service from BSNL India.

The main problem people seem to be facing that even when the ADSL connection is working, gets connected, they can't browse any site, nor can they connect to any host using any other mechanism such as FTP. When they try to ping an IP address other than that of the modem, they see an error message something like:

Reply from 192.168.0.1: Destination net unreachable

Don't get me wrong here, but doing anything slightly out of the normal operation in Linux does require some patience and conscious efforts. Of course, there's the exhilarating feeling when you finally get it done, but you just can't help think that it would've been better if it just worked at the first attempt. Configuring and starting ADSL broadband connections is one of those things. Here's a procedure that would get you set up quickly and completely:

You'll need: one full installation of a standard Linux distribution, your username-password for the ADSL connection, one ADSL modem with an Ethernet interface (with a DHCP server) and, most importantly, one working ADSL connection.

Steps:
  1. Login to your Linux box as root. This is not recommended, but the only problem with using a non-root account is that you'll have to give the password a lot of times.
  2. Configure your Ethernet interface (eth0 or some such, ethX - we'll stick to the name eth0) to get the IP information using DHCP. But, uncheck the option to do this at system startup. This is probably the single most important thing to be remembered. Setting it to run DHCP at startup is the reason the problem stated above appears. More later.
  3. Do one of the two:
    1. Use the script adsl-setup to get the system to store your ADSL username/password and any other details that you may wish to provide. The one option that is important is the DNS settings - this is set to SERVER in most cases and this means that your ISP will provide the DNS server settings when you connect.
    2. Use a graphical client such as kpppoe (which is internally a popular client called RpPPPoE) to provide the ADSL username/password and other settings. This is even simpler as the user interface is one of the most minimal I've seen.
  4. Make sure that the Ethernet interface (eth0) is down.
  5. If you used 3.1 above, you can use another script adsl-start to open ADSL connection. Only in this case, you will have to change the permissions as per which users of your system you want to be able to connect using this script.
    If you used 3.2 above, all you need to do is click on the "Start" button on the kpppoe window. There is an option in the settings of kpppoe to enable other users of the system to be able to use it to open up access to the Internet.
  6. Once you're done, use adsl-stop to close the ADSL connection if you used the adsl-setup path or click the button "Stop" to close it if you used kpppoe.
Now, the reason for the warning in bold letters. As you may know, to connect to any other machine over the Ethernet, the system requires what is called a gateway, which can route our message to that machine. If the Ethernet interface does come up during system startup, or if it is up already when we try to open the ADSL connection, this means that DHCP has been performed and the interface already has an IP address as well as gateway. Now, the crux of the matter is that scripts which bring up eth0 also set the default route to this gateway.

What adsl-start or kpppoe do is they bring up the adsl and pppd services, enabling the machine to create a PPP interface on top of eth0 over which all our traffic flows. Ideally, once that is done, the default route should be set to the gateway beyond the ADSL modem - the ISP's gateway. Unfortunately, these programs invoke pppd with an option which tells it not to create the default route if one exists already.

That's where the warning comes in. If eth0 is already up, there is already a default route to the ADSL modem, hence, no default route to the ISP's gateway. Since it is the ISP's gateway - and not the ADSL modem - which knows how to reach the DNS servers, and all machines on the Internet, we can't reach all these with the default route going into the ADSL modem. And the weird "Destination net ..." message starts showing up.

The easiest way out is to follow the procedure outlined above. The difficult way out is to change all the scripts so that such a situation never occurs. But that, probably is a topic for another time. Enjoy broadband, in the meanwhile.

2 comments:

Rushikesh said...
This comment has been removed by the author.
Rushikesh said...

Well, its interesting that your are maintaining a blog. Not as that you are posting many things....But, its a good habit...
There are somethings, about which you think....and you reach to some solution. Or somethings your search...Over the years, you tend to forget and at-last you just don't remember about it.
So, writing and publishing is best way.
Good job....