Howto: Ubuntu Linux convert DHCP network configuration to static IP configuration

=> Network ID: 192.168.1.0
=> Broadcast IP: 192.168.1.255
=> Gateway/Router IP: 192.168.1.254
=> DNS Server: 192.168.1.254 <p>Open network configuration file
$ sudo vi /etc/network/interfacesOR$ sudo nano /etc/network/interfaces</p><p>Find and remove dhcp entry:
iface eth0 inet dhcp</p><p>Append new network settings:</p><p>iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254

Save and close the file. Restart the network:
$ sudo /etc/init.d/networking restart</p><h3>Task: Define new DNS servers </h3><p>Open /etc/resolv.conf file
$ sudo vi /etc/resolv.conf </p><p>You need to remove old DNS server assigned by DHCP server:
search myisp.com
nameserver 192.168.1.254
nameserver 202.54.1.20
nameserver 202.54.1.30

Save and close the file.</p><h3>Task: Test DNS server</h3><p>$ host cyberciti.biz</p><h3>Network command line cheat sheet</h3><p>You can also use commands to change settings. Please note that these settings are temporary and not the permanent. Use above method to make network changes permanent or GUI tool as described below.</p><h3>Task: Display network interface information</h3><p>$ ifconfig</p><h3>Task: Take down network interface eth0 / take a network interface down</h3><p>$ sudo ifconfig eth0 downOR $ sudo ifdown eth0 </p><h3>Task: Bring a network interface eth0 up </h3><p>$ sudo ifconfig eth0 upOR$ sudo ifup eth0 </p><h3>Task: Change IP address and netmask from command line</h3><p>Activate network interface eth0 with a new IP (192.168.1.50) / netmask:
$ sudo ifconfig eth0 192.168.1.50 netmask 255.255.255.0 up</p><h3>Task: Display the routing table </h3><p>$ /sbin/route OR$ /sbin/route -n
Output:</p><pre>Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface localnet * 255.255.255.0 U 0 0 0 ra0 172.16.114.0 * 255.255.255.0 U 0 0 0 eth0 172.16.236.0 * 255.255.255.0 U 0 0 0 eth1 default 192.168.1.254 0.0.0.0 UG 0 0 0 ra0 </pre><h3>Task: Add a new gateway </h3><p>$ sudo route add default gw 172.16.236.0</p><h3>Task: Display current active Internet connections (servers and established connection)</h3><p>$ netstat -nat</p><h3>Task: Display open ports</h3><p>$ sudo netstat -tulpOR$ sudo netstat -tulpn</p><h3>Task: Display network interfaces stats (RX/TX etc)</h3><p>$ netstat -i</p><h3>Task: Display output for active/established connections only</h3><p>$ netstat -e
$ netstat -te
$ netstat -tue</p><p>Where,</p><ul>

  • -t : TCP connections
  • -u : UDP connections
  • -e : Established
  • </ul><h3>Task: Test network connectivity</h3><p>Send ICMP ECHO_REQUEST to network hosts, routers, servers etc with ping command. This verifies connectivity exists between local host and remote network system:
    $ ping router
    $ ping 192.168.1.254
    $ ping cyberciti.biz</p><p>See simple Linux system monitoring with ping command and scripts for more information.</p><h3>Task: Use GUI (Graphical Configuration) network Tool</h3><p>If you are new, use GUI configuration tool, type the following command at terminal:
    $ network-admin &</p><p>Above command is Ubuntu’s GUI for configuring network connections tool.</p><h3>Final tip - Learn how find out more information about commands</h3><p>A man page is your best friend when you wanted to learn more about particular command or syntax. For example, read detailed information about ifconfig and netstat command:
    $ man ifconfig
    $ man netstat

    Just get a short help with all command options by appending –help option to each command:
    $ netstat –help</p><p>Find out what command is used for particular task by searching the short descriptions and manual page names for the keyword:
    $ man -k ‘delete directory’
    $ apropos -s 1 remove</p><p>Display short descriptions of a command:
    $ whatis rm
    $ whatis netstat</p>