Static (Fixed) IP Address in Debian & Ubuntu Linux
Updated 2012-01, Ubuntu 10.04.03 LTS.
Background
To check and see the IP address assigned to your network interfaces at any point, run ifconfig as the superuser:
me@myhost$ sudo ifconfig
This page shows how to set up static IP addresses for a personal computer on a home network using both a GUI interface and the direct method of editing the appropriate configuration file. This is important in my home network for using NFS Linux-to-Linux file sharing and for using Virtual Hosts in a private LAN development environment.
Method 1: Gnome (Default Ubuntu or Debian) Networking GUI
The default desktop environment for Debian and Ubuntu Linux is Gnome, and these Graphical User Interface (GUI) notes refer only to the Gnome desktop. To administer the networking settings, go to System --> Peferences --> Network Connections. You will see a window like the one below.
You may see multiple entries where I only have one. Click on the network card that you want to give a fixed IP to and then click on the "Edit" button. For a wired connection, you will probably see the "Wired" tab of the dialog box below, showing your NIC's MAC address. Click on the "IPv4 Settings" tab to set a fixed IP address.
- CLick on the "Add" button.
- Click in the "Address" box and enter an IP address ON YOUR NETWORK (i.e., only change the last number).
- Netmask = 255.255.255.0
- Gatway = 192.168.1.1 (10.0.0.1, etc. It is your ISP Modem's address)
- DNS sever = Maybe you can leave blank. Otherwise, it is your ISP Modem.
- Check "Available to all users" and click "Apply".
- Restart the networking service. See below.
NOTE: I have successfully forced a fixed IP address using the graphical method and it does NOT show up in the manual configuration file listed below. I suggest you use one method only and stick to it.
Method 2: Manually Editing the Configuration File
I found out that the file you need to edit to set networking interfaces is /etc/network/interfaces . Below is a *section* of the file that deals with your first Ethernet card only (eth0). I don't understand why everything is there, so use at your own risk. I left extra information in from the file I copied it from. The "#" mark is a comment symbol and my system worked without entering these extra values. If you wanted to try this, you would edit the section for eth0 and not add an additional entry.
NOTE: You need to edit this file with "superuser" priveledges. If you are the only use in Ubuntu, then you qualify. In Debian, you can use the "su" command to become root. In Ubuntu you would use "sudo" followed by your editor command. Edit the file in a terminal using "nano", or even use "gedit" since this is a desktop home network.
# A section of the file /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.1.21
netmask 255.255.255.0
#network x.x.x.x
#broadcast x.x.x.x
gateway 192.168.1.1
Restart of Networking Service is Required
You would need to restart the networking service (superuser again) no matter which method you used to change the network interface. You can always reboot your computer to make sure that networking is restarted, or you can issue the command below in a terminal.
me@myhost$ sudo /etc/init.d/networking restart




