Thursday, December 21, 2006

Static IPs in Debian-based Linux

Here's a brief overview of how to set up an internet connection using a static IP address on Debian-based Linux systems. Most large networks nowadays use DHCP to get a user an IP address, but knowledge of static IP configuration can still be helpful in a lot of situations. First, edit the /etc/network/interfaces file as a superuser so that the entry for the desired interface looks something like this (replace x's with numeric values):

iface eth0 inet static # static, as opposed to dhcp... replace eth0 with desired interface
address xxx.xxx.xxx.xxx # ip address you want assigned to this computer
netmask xxx.xxx.xxx.xxx # subnet mask
network xxx.xxx.xxx.xxx # optional
broadcast xxx.xxx.xxx.xxx # optional
gateway xxx.xxx.xxx.xxx # gateway (usually router/firewall) ip address

Once you have done this, restart your network interfaces with sudo /etc/init.d/networking restart

The gateway can also be specified on the command line if it's not in the interfaces file: sudo route add default gw xxx.xxx.xxx.xxx The command netstat -nr can show the routes, including gateways, that the kernel is currently using.

To explicitly release a dhcp connection, do something like dhclient -r eth0

If your computer and network is set up correctly, you should now be able to ping your gateway and access sites on the internet by IP address. However, in order to access sites by name you need the help of DNS. Add entries to the /etc/resolv.conf file as a superuser in this format (you can have as many as you want):

nameserver xxx.xxx.xxx.xxx

Now, if you point your browser to a domain name like www.yahoo.com, you should be able to get there. Welcome to t3h 1nt3rw3b. You can also do all the above by accessing the System->Administration->Network menu.

Links:
Update (in light of ubuntu-users post and responses):
For switching from one interface configuration to another (assuming eth0 and correct /etc/network/interfaces):
  1. sudo ifdown eth0
  2. edit /etc/network/interfaces
  3. sudo ifup eth0
SIOCDELRT: No such process means something is screwy. You probably have the wrong number (i.e. gateway) somewhere. Haven't determined exactly what this means.

No comments: