How to Configure Network Ubuntu 12.10 / 12.04 / 11.10


To start accessing internet or sharing other resources on the network you have to configure TCP/IP settings of you ethernet card. In ubuntu you can configure network settings through GUI and CLI. It can be a difficult task for newbie user who is switching from other OS to ubuntu as the look and feel of ubuntu will be different in comparison of other OS (specifically windows). In this tutorial we will be seeing how to configure TCP/IP setting via GUI as well as CLI.

Before starting the configuration part, you have to know whether you will be configuring IP manually or IP will be assigned directly through DHCP server.

In case of manual IP assignment you should know IP address, subnet mask, gateway and DNS. In this tutorial I am using following information. Remember you don’t require it in case of DHCP configuration.

IP : 192.168.1.100
NETMASK : 255.255.255.0
GATEWAY : 192.168.1.1
BROADCAST : 192.168.1.255
NETWORK : 192.168.1.0
DNS : 8.8.8.8

Method 1 : Configure network GUI mode

Step 1 : First find out the network interface to configure. Open a terminal and run ifconfig

ifconfig

Result will be something similar to below screenshot.

Step 2 : We will be assigning IP address to eth0 adapter. To do the same Click on “System Setting” and select “Network”

Step 3 : As eth0 is wired connection click on “wired”. Choose “ON” option and click on “Configure” button.

Step 4 : Go to “IPv4 Settings” tab. In case of DHCP / Automatic configuration choose “Automatic (DHCP)” option in “method”

In case of manual configuration select “Manual” option in “method”. Click on “Add” button. Enter IP Address, netmask and gateway information. Also enter DNS Server. In this example I am using google DNS server’s IP.

After finishing it up click on “Save” button.

Step 5: To confirm the setting again run “ifconfig” command and check the “eth0″ interface settings. In case of successful configuration you will see something like below screenshot.

Method 2 : Configure network CLI Mode

Step 1 : First find out the network interface to configure. Open a terminal and run ifconfig

ifconfig

Result will be something similar to below screenshot.

Step 2 : We will be assigning IP address to eth0 adapter. Open a terminal and type

sudo vi /etc/network/interfaces


Step 3: Now you need to add eth0 information in this file.
In case of DHCP / Automatic IP assignment enter following line and save this file.

iface eth0 inet dhcp

In case of manual IP assignment enter following line and save this file.

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.1
dns-nameserver 8.8.8.8

Configure network in Ubuntu
Step 4: The file resolv.conf should no longer be edited manually. It is updated by the resolvconf script. To prevent resolvconf to still generate our resolv.conf file with our old dhcp settings we have to delete these two files. For more explaination see this post

Run following commands

sudo rm /run/resolvconf/interface/eth0.dhclient
sudo rm /run/resolvconf/interface/original.resolvconf

Step 5: Uninstall the dhcp client otherwise it will overwrite our changes on the next renew cycle

sudo apt-get remove isc-dhcp-client

Step 6: Restart the network using following command

sudo nohup sh -c "ifdown eth0 && ifup eth0"

The result can be check with the cat command:

sudo cat nohup.out

It should look something like this:

ssh stop/waiting
ssh start/running, process 3981

Step 7 Cross verify the configuration
Step 7.1 The resolv.conf should now only contain the dns settings that we provided for our interface (eth0) check with:

sudo cat /etc/resolv.conf

The result should look like this:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8

Step 7.2 Check that the correct ip address has been set:

ifconfig eth0 | grep 'inet addr'

Result:

inet addr:192.168.1.98 Bcast:192.168.1.255 Mask:255.255.255.0

Step 7.3 Check that dns lookup works:

nslookup techienote.com

Result:

Server:         8.8.8.8
Address:        8.8.8.8#53
 
Non-authoritative answer:
Name:   techienote.com
Address: 174.122.2.251

Note that address in the reply might have changed after this was written.

Step 7.4 And if we have gotten this far we have most likely set our gateway and other network parameters correctly and should also be able to reach the internet:

ping techienote.com

Result:

PING techienote.com (174.122.2.251) 56(84) bytes of data.
64 bytes from fb.2.7aae.static.theplanet.com (174.122.2.251): icmp_req=1 ttl=50 time=338 ms
64 bytes from fb.2.7aae.static.theplanet.com (174.122.2.251): icmp_req=2 ttl=50 time=339 ms
64 bytes from fb.2.7aae.static.theplanet.com (174.122.2.251): icmp_req=3 ttl=50 time=339 ms

For more such content stay tuned with techienote.

Subscribe / Share

Article by Vidyadhar

My name is Vidyadhar Sarmalkar & I work as a consultant and have done RHCE & CCNA.
Vidyadhar tagged this post with: , , , , , , , , , , , , , , , , , , , , , , Read 272 articles by

Leave a Reply

rss twitter facbook

Categories

Archives