Ubuntu Networking Configuration Using Command Line

Sponsored Link
The basics for any network based on *nix hosts is the Transport Control Protocol/ Internet Protocol (TCP/IP) combination of three protocols. This combination consists of the Internet Protocol (IP),Transport Control Protocol (TCP), and Universal Datagram Protocol (UDP).

By Default most of the users configure their network card during the installation of Ubuntu. You can however, use the ifconfig command at the shell prompt or Ubuntu's graphical network configuration tools, such as network-admin, to edit your system's network device information or to add or remove network devices on your system

Configure Network Interface Using Command-Line

You can configure a network interface from the command line using the networking utilities. You configure your network client hosts with the command line by using commands to change your current settings or by editing a number of system files.

Configuring DHCP address for your network card

If you want to configure DHCP address you need to edit the /etc/network/interfaces and you need to enter the following lines replace eth0 with your network interface card

sudo vi /etc/network/interfaces

Note :- Use vi editor if you don't have GUI installed

If you have GUI use the following command

gksudo gedit /etc/network/interfaces

# The primary network interface -- use DHCP to find our address
auto eth0
iface eth0 inet dhcp

Configuring Static IP address for your network card

If you want to configure Static IP address you need to edit the /etc/network/interfaces and you need to enter the following lines replace eth0 with your network interface card

sudo vi /etc/network/interfaces

Note :- Use vi editor if you don't have GUI installed

If you have GUI use the following command

gksudo gedit /etc/network/interfaces

# The primary network interface

auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
network 192.168.3.0
broadcast 192.168.3.255

After entering all the details you need to restart networking services using the following command

sudo /etc/init.d/networking restart

Setting up Second IP address or Virtual IP address in Ubuntu

If you are a server system administrator or normal user some time you need to assign a second ipaddress to your Ubuntu machine.For this you need to edit the /etc/network/interfaces file and you need to add the following syntax.Below one is the only example you need to chnage according to your ip address settings

sudo vi /etc/network/interfaces

Note :- Use vi editor if you don't have GUI installed

If you have GUI use the following command

gksudo gedit /etc/network/interfaces

auto eth0:1
iface eth0:1 inet static
address 192.168.1.60
netmask 255.255.255.0
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x

You need to enter all the details like address,netmask,network,broadcast and gateways values after entering all the values save this file and you need to restart networking services in debian using the following command to take effect of our new ipaddress.

After entering all the details you need to restart networking services using the following command

sudo /etc/init.d/networking restart

Setting your ubuntu stytem hostname

Setting up your hostname upon a ubuntu installation is very straightforward. You can directly query, or set, the hostname with the hostname command.

As an user you can see your current hostname with

sudo /bin/hostname

Example

To set the hostname directly you can become root and run

sudo /bin/hostname newname

When your system boots it will automatically read the hostname from the file /etc/hostname

If you want to know more about how to setup host name check here

Setting up DNS

When it comes to DNS setup Ubuntu doesn't differ from other distributions. You can add hostname and IP addresses to the file /etc/hosts for static lookups.

To cause your machine to consult with a particular server for name lookups you simply add their addresses to /etc/resolv.conf.

For example a machine which should perform lookups from the DNS server at IP address 192.168.3.2 would have a resolv.conf file looking like this

sudo vi /etc/resolv.conf

Note :- Use vi editor if you don't have GUI installed

If you have GUI use the following command

gksudo gedit /etc/resolv.conf

enter the following details

search test.com
nameserver 192.168.3.2

Sponsored Link

You may also like...

140 Responses

  1. Sureinlux says:

    Finally to top it off, you can check whether the DNS is working or not, you can use the following command:

    you should a reply like this…

  2. Sureinlux says:

    Sorry for the incomplete reply…

    the code is:
    host gmail.com

    the reply should be:
    gmail.com has address 216.239.57.83
    gmail.com has address 64.233.161.83
    gmail.com has address 64.233.171.83
    gmail.com mail is handled by 10 alt2.gmail-smtp-in.l.google.com.
    gmail.com mail is handled by 50 gsmtp163.google.com.
    gmail.com mail is handled by 50 gsmtp183.google.com.
    gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.
    gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.

  3. david says:

    Ain’t it wonderful how none of this applies to other Linux disto’s, RedHat for example. Why in world can Linux distro’s agree on something as common as networking. Sad, very sad!

  4. Vista says:

    Great – thanks for the info

  5. netztier says:

    No “gateway” configuration for the second/virtual IP address! If you add a second gateway configuration, your routing table will end up with two default entries – which is a bad thing to have.

    We’re not correcting such a configuration error for the first time in the Ubuntu Forums. Please make sure that the user understands the implications and dangers of having more than one default route in the routing table, or recommend not to have “gateway” line for the secondary IP address at all.

  6. trancepose says:

    dude, different distros and different approaches speed up improvement of the overall linux system. yeah, it’s so pity no codes of this distro applies that distro, but think of the advantages and and you’ll see they have already overtook the disadvantage of coding(and maybe gaming is another for gamers-not 4 me. i have passed to linux in order to stop gaming. gaming wastes 2 much time)

  7. adbasque says:

    Hi there!
    Linux is great yes no doubt about it
    but, i would like to see these advantages you’re talking about
    Trancepose, just think of the standarzation (standarsation) like of protocols and Wc3 etc.. if everybody codes as he pleases it will be a huge mess and nobody would be able to move forward.
    i am sorry but the way i see it, it’s a form of sadisme, between one disto and another everything has moved and everything is different, i don’t call this evolution i call it *BS* bureaucracy, politicized, etc.. red had, fedora, suse, ubuntu etc.. they can at least agree on certains things even if they want to be different. i use linux for almost 17 years now.
    i won’t call them by their name but all “Linux” or unix.
    end of story
    Regards

  8. Vitamin Carrot says:

    lol the above is no more than a poor attempt at pseudo intellectualism

  9. Kuvax says:

    Hey people:

    I get an error after changing eth0 ip:

    yo# /etc/init.d/networking restarting
    *Reconfiguring network interfaces…
    Don’t seem to be have all the variables for eth0/inet.
    Failed to bring up eth0

    What can i do?
    Thank

  10. Kuvax says:

    Hey people:

    I get an error after changing eth0 ip:

    auto eth0
    iface eth0 inet static
    adress 10.10.4.55
    gateway 10.10.1.126
    netmask 255.255.0.0
    network 10.10.4.0
    broadcast 10.10.255.255

    then:

    yo# /etc/init.d/networking restarting
    *Reconfiguring network interfaces…
    Don’t seem to be have all the variables for eth0/inet.
    Failed to bring up eth0

    i have a 8.04 ubuntu

    What can i do?
    Thank

  11. admin says:

    check the following command

    # /etc/init.d/networking restarting

    to

    # /etc/init.d/networking restart

    and check

    run the following command and post the output

    ifconfig

  12. Kuvax says:

    Hi:

    It just show the normal lookup interface (127.0.0.1) doesn’t bring up eth0

    thank for the fast reply

  13. Kuvax says:

    what else i have to do???

  14. admin says:

    ok here is the problem

    it should be

    address 10.10.4.55

    not

    adress 10.10.4.55

  15. Kuvax says:

    Ohhhhh thanks a lot!!!!, im a cuban linux admin and now im migrating to ubuntu from centos.

    I normally speak spanish 😀 my mistake

  16. Steven White says:

    Hello,

    Using Ubuntu 6 for requirements of Zimbra mail server.

    I followed the above for the file /etc/network/interfaces but there seems to be something having to do with routing that’s keeping traffic from flowing.

    I’ve followed instructions found elsewhere for a ‘route add’ command but still no dice.

    If you can help, let me know what output you’d like to see here to help with troubleshooting.

    Thanks,
    Steven

  17. Stephen says:

    Any chance of a guide for wifi connections from the command line.

  18. superman91 says:

    Hi all.

    Please can you assist me with adding a wireless card on my Ubuntu server through command line..

    Many thanks

    Superman

  19. Santiago says:

    Good material, this is very useful for people that can’t configure without a gui….

  20. Raul says:

    Hi, i have a problem, i need many hosts setted up in my hosts tab in my network configuration. Those hosts are Anfitriones in spanish.
    The problem is when i save a profile containing all the hosts it does not change to the profile, so i need to add it temporarily and when I add a new host the last added is deleted.
    I think there is something wrong with the interface. Can i change the info manually in the terminal?. Do you know about the commands to achieve this?-
    Thanks!

  21. Gezae says:

    could you Send me important practical notes on Ubuntu linux

  22. Dominique says:

    Trying to understand linux …

    There are 4 NIC on a PC (the goal is to learn network, Linux, managing Firewalls, NAT etc … )

    My /etc/network/interfaces appears like that :

    auto lo
    iface lo inet loopback

    But eth0 is connected to a router (connecting the PC to the rest of the world …).

    Where does Linux get the information ? (starting eth0 … etc … NB: the /etc/resolv.conf contains the address of the router and ISP)

  23. R says:

    I am having trouble getting network connection working in Ubuntu 7.10. I’ve pretty much followed all suggested solutions above and still stranded. I am trying to setup DHCP connection.

    Can someone shed some light on what could be wrong?

    My /etc/network/interfaces file looks like this:

    auto lo
    auto eth0
    iface eth0 inet dhcp
    iface lo inet loopback

    #auto eth0
    #iface eth0 inet dhcp

    #auto eth0

    And here’s what I get from ifconfig:

    eth0 Link encap:Ethernet HWaddr 00:40:2B:7C:4D:95
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
    Interrupt:20

    eth0:avah Link encap:Ethernet HWaddr 00:40:2B:7C:4D:95
    inet addr:169.254.6.40 Bcast:169.254.255.255 Mask:255.255.0.0
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    Interrupt:20

    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:34 errors:0 dropped:0 overruns:0 frame:0
    TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:2896 (2.8 KB) TX bytes:2896 (2.8 KB)

    Here’s what sudo /etc/init.d/networking restart returns:

    Listening on LPF/eth0/00:40:2b:7c:4d:95
    Sending on LPF/eth0/00:40:2b:7c:4d:95
    Sending on Socket/fallback
    There is already a pid file /var/run/dhclient.eth0.pid with pid 134519120
    Internet Systems Consortium DHCP Client V3.0.5
    Copyright 2004-2006 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/

    Listening on LPF/eth0/00:40:2b:7c:4d:95
    Sending on LPF/eth0/00:40:2b:7c:4d:95
    Sending on Socket/fallback
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 5
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 12
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 10
    No DHCPOFFERS received.
    No working leases in persistent database - sleeping.

  24. Joenieburg says:

    Try this one.
    possible is the nic wrong configure in your kernel.
    vi /etc/udev/rules.d/70-persisten-net.rules
    remove the line what end on the nic that doesn’t work.(but also write down the driver name after the 20394:20000 (drivername)
    exit vi
    /etc/init.d/udev restart ( this will create the line again in the right way.
    The remove and add the driver.
    modprobe -r (drivername)
    modprobe (drivername

    /etc/init.d/networking restart

  25. Stephen Baker says:

    Don’t do what I did which is spend 2 hours trying to work out why my network connection wouldn’t work on the Virtual PC for the Ubuntu install.. constantly trying different settings on the wired network connection only to realise I wasn’t using the wired internet connection, I was using wireless! Very silly.

  26. D Srinivas says:

    I am srinvas,
    In my machine In /etc/iftab the mack address are
    eth0 mac 00:13:21:b5:31:6f arp 1
    eth1 mac 00:13:21:b5:31:70 arp 1
    But when I logged in I need to ifup eth2 or eth3.
    Please suggest some problem
    thank you

  27. B Gunkel says:

    Hi there. I am having a problem starting my second network card in ubuntu 8.04 LTS server edition. When I use ifconfig it shows me eth0 only. Please help.

  28. RudyD says:

    Hi!

    I would like to set networking in a script p.e. in live mode ubuntu 8.10
    It is ok, I can set with ifconfig the address, and the route, but I can not set the DNS servers. With
    sudo echo “nameserver ip.of.name.server” >> /etc/resolv.conf
    It responds with an “Permission denied” error.
    Is someone have any idea for a working solution?
    TIA!

    R

  29. admin says:

    @RudyD

    When you run the command using sudo it will prompt for password so you need to passthat password also otherwise it doesn’t work

  30. RudyD says:

    @Admin

    There is no problem with sudo. It is a live system directly started from cd. I just want to set networking more quickly than clicking around several times.
    So there is no need for password in that case.

    I think it is about the redirection. If i use sudo su, it does the trick. I have tried to include the rest of the line into backwards apostrophe, and in brackets {} but did not worked.

    Especially it is a new ubuntu 8.10 and I expect that there can be an other way to update dns stuff. (Does someone know how to script network-manager!? B-) )

    Thanks for your quick reply!

Leave a Reply

Your email address will not be published. Required fields are marked *