Technical Recipes

How to configure static IP on Debian

1. Back up the original network interface file if it exists
 
    $ sudo cp /etc/network/interfaces /etc/network/interfaces.bak
 
2. Find the original network settings
 
    $ sudo ifconfig
 
3. Edit the network interface file

    Keep the loopback network interface unchanged, and comment out the original settings which uses DHCP for the primary network interface, then add the static address and other information to the primary network interface according to the information you find from ifconfig.
	
    $ sudo vi /etc/networking/interfaces
    # allow-hotplug eth0
    # iface eth0 inet dhcp
 
    auto eth0
    iface eth0 inet static
    # set your static IP below
    address 192.168.1.220
    netmask 255.255255.0
    gateway 192.168.1.1
	
    Don't add the following two lines because they are only necessary if you want to act as a router:
 
       network 83.222.248.0
       broadcast 83.222.248.255
 
4. Restart the network service
 
    $ sudo /etc/init.d/networking restart
 
5. Change settings in virtual machines if necessary
 
    5.1 VMWare Player
		Make sure the network connection type is Bridged and it's connecting to the proper host hardware network card
 
    Player -> Manage -> Virtual Machine Settings ... -> Network Adapter -> Bridged -> Configure Adapters:
 
    5.2 VirtualBox
        Make sure the network connection type is: Host-only and change the virtual Network Adaptor on the host to have the same static IP address 192.168.1.220 and the other information according to the information you find from Command Prompt:
 
    > ipconfig /all
	
    Control Panel -> Network and Sharing Center -> VMware Network Adapter VMnet1 -> Properties -> Internet Protocol Version 4 -> Properties -> Use the following IP address: 192.168.1.220
	
    5.3 Verify the static IPs are available from the host
 
    > ping 192.168.1.220