February 5, 2007 · Networking · Email This Post

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

Incoming search terms:

Related posts

138 Comments to “Ubuntu Networking Configuration Using Command Line”

  1. Rashid says:

    Hi,

    I have tried both dhcp and static configurations but my ubuntu 7.10 doesn’t seem to pick up network settings. My linux is connected to an ADSL router via ethernet card (eth0). It is the only interface I have on my PC. But after reading this very simple tutorials and all the tries my distro isn’t coming up on LAN nor it can use internet.

    Could it be that my eth0 is busted or something, Any ideas?

    [Reply]

  2. zazkia says:

    Hi i have an idea, but no solution.
    I guess it might be that by default, the eth0 is set to ipv6, whereas I am pretty sure that my provider offers me ipv4.
    Simply typing in inet4 instead of inet does not change ifpriv to

    zazkia@floyd:~$ ifconfig
    eth0 Link encap:Ethernet HWaddr 00:16:17:53:52:0f
    inet6 addr: fe80::216:17ff:fe53:520f/64 Scope:Link

    At the moment I have no internet because of it, grrrrr

    [Reply]

  3. zazkia says:

    sorry that was vague
    :
    typing in etc/network/interfaces :

    auto eth0
    iface eth0 inet4 dhcp

    still leads to inet6 in the ifconfig command.

    [Reply]

  4. B Gunkel says:

    Hi all. Please help me with my ubuntu 8.04. I can not access it from any pc on the network. I have webmin installed and it works when I am logged in to the ubuntu pc, but any pc windows or linux on the network can not ping it. My linux pc does not ping any pc on the network as well.

    [Reply]

  5. runout says:

    Thanks for that manual! Just a 1 spelling mistake, and all day were lost… I found the answer there. Funny =)

    [Reply]

  6. Paul Hoffman says:

    This article does not explain how to set up both IPv4 and IPv6 addresses on a single interface, which is a common task. After much trial-and-error, I figured it out. For future generations:

    auto eth0
    iface eth0 inet static
    address 1.2.3.4
    netmask 255.255.255.0

    iface eth0 inet6 static
    address 2001:0db8:1234:5678::1
    netmask 64

    In specific, you do not use the “eth:1″ hack in the article and you do not use “auto” twice.

    [Reply]

  7. Chiefdnd says:

    New to Ubuntu, installed Ubuntu 8.10 on a dell Visto 200, can see internal network and printers, but cannot connect to the internet. Can connect to intenet via windows XP systems.
    PC –> SG580 –> ADSL
    PC – internal network
    SG580 – Secure Computing Firewall (http://www.securecomputing.com/index.cfm?skey=1485)
    ADSL – DSL modem
    Thank you,
    Chiefdnd

    [Reply]

  8. Matey says:

    Does Anyone Know where I tell the system the address to the DHCP Server?

    This is a xen (Virtual machine) and also is OFF SITE in another location, Our DHCP is on our network here and I dont even think those ppl who have our server have any DHCP (not for free any way) SO I am trying to connect using our DHCP here, But No where do I see any lit.on this?
    I get the same error when I do dhclient on eth1 …..> sleeping!?

    I have looked many files, I can ping outside but I cant ping this box from another machine and it is connected to the internet?!
    So I think if I just get it to talk to our LAN here I’ll be all right?
    Any suggestions???

    (AND THE FONT HERE IS TEARING MY EYES UP GEE I AM NOT AN ANT I AM A HUMAN BEING!
    GEE!
    THANK YOU!

    [Reply]

  9. mrsato says:

    Chiefdnd, check to be sure your linux pc has the same gateway IP as the XP machines. With no gateway at all, or yourself as the gateway, you will likely be able to see everything on your subnet, but once you have to go over a hop, you won’t get anywhere.

    [Reply]

  10. Matey says:

    Thank You all for the replies. Specially to the Admin for a complete How To!

    I got it right now. It is not so bad, but I agree with DAVID!

    I mean I have worked with Ubuntu for over a year now but I recently installed RedHat and upon using it I was lost! I had no idea that the different dist. versions of Linux were so much different, most of the commands I learned in Ubuntu won’t work in Redhat and vice versa! :(

    I guess I have to start writing scripts to translate the different commands among different flavors of Linux.
    simple commands I mean not really scripts.like in Redhat you do a vi apt-get then put yum and save it. chmod 755 and mv to /bin

    then every time you type in apt-get it puts in yum.
    its not so easy for me though since I dont know how to pass switches into this but at least you have a place where you can store diff. commands .
    May be someone will figure this out?
    Thanks again.

    [Reply]

  11. Mathew Shijoy says:

    Thanks……………..

    [Reply]

  12. Unreal says:

    After following these steps, Ubuntu will no longer boot up. I cant even get into a terminal. Thanks.

    [Reply]

  13. Grimm08 says:

    I am trying to configure Bind for the first time. I have configure BIND exculty as said in the guide, when I restarted the BIND server it will now not restart. If any one know why please let me know. The only thing I did not include was the in both the zones file, I did not include was admin.domainname.com.

    [Reply]

  14. naveed says:

    how can i configure alfa usb wireless devise on ubunto ??
    It works fine with vista, but with ubuntu i see the connection establish icon but not able to browse internet nor able to ping the gateway 192.168.1.1.
    with i type ifconfig i see the following ipaddress 192.168.1.9.

    [Reply]

  15. naveed says:

    find below the results, if anyone can help me with this it will be great.

    root@r-nav:/etc/network# iwconfig

    wlan1

    IEEE 802.11bg ESSID:”Abc”
    Mode:Managed Frequency:2.462 GHz Access Point:

    00:1B:9E:BE:AA:03
    Bit Rate=54 Mb/s Tx-Power=27 dBm
    Retry min

    limit:7 RTS thr:off Fragment thr=2352 B
    Encryption key:off
    Power

    Management:off
    Link Quality=14/100 Signal level:65/65
    Rx invalid

    nwid:0 Rx invalid crypt:0 Rx invalid frag:0
    Tx excessive retries:0 Invalid

    misc:0 Missed beacon:0

    root@r-nav:/etc/network# ping google.com -c 4

    ping: unknown host google.com

    [Reply]

  16. Mehdi says:

    I think there is a problem with your wireless settings?
    Can you run the command dhclient and see what you get in return?

    [Reply]

  17. naveed says:

    Hi Mehdi,

    thanks for the reply, please find below the logs.

    I have installed the latest drivers as shown below.

    root@r-nav:/tmp/rtl8187b# make install
    make: `install’ is up to date.
    —————–

    root@r-nav:/tmp/rtl8187b# dhclient
    Internet Systems Consortium DHCP Client V3.1.1
    Copyright 2004-2008 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/

    wmaster0: unknown hardware address type 801
    wmaster0: unknown hardware address type 801
    Listening on LPF/pan0/8e:a0:33:b0:48:cb
    Sending on LPF/pan0/8e:a0:33:b0:48:cb
    Listening on LPF/wmaster0/
    Sending on LPF/wmaster0/
    Listening on LPF/eth1/00:17:31:1c:23:0e
    Sending on LPF/eth1/00:17:31:1c:23:0e
    Listening on LPF/wlan1/00:c0:ca:1b:d3:d5
    Sending on LPF/wlan1/00:c0:ca:1b:d3:d5
    Listening on LPF/eth0/00:17:31:1c:29:4d
    Sending on LPF/eth0/00:17:31:1c:29:4d
    Sending on Socket/fallback
    DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 3
    DHCPDISCOVER on pan0 to 255.255.255.255 port 67 interval 3
    DHCPDISCOVER on wmaster0 to 255.255.255.255 port 67 interval 7
    DHCPDISCOVER on wlan1 to 255.255.255.255 port 67 interval 3
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 10
    DHCPDISCOVER on wlan1 to 255.255.255.255 port 67 interval 9
    DHCPDISCOVER on wmaster0 to 255.255.255.255 port 67 interval 8
    DHCPDISCOVER on pan0 to 255.255.255.255 port 67 interval 7
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 9
    DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 5
    No DHCPOFFERS received.
    No working leases in persistent database – sleeping.

    appreciate your help.

    [Reply]

  18. vesa says:

    I made all changes on sudo /etc/init.d/networking saved it and tryed restart it, but I get the following error: postconf: fatal: open /etc/postfix/main.cf : No such file or directory

    What should I do

    PS! Thats my first Linux installation, so be very specific, thanks

    [Reply]

  19. vesa says:

    sorry my bad.
    I made all changes on sudo vi /etc/network/interfaces not on /etc/init.d/networking

    [Reply]

  20. itics says:

    Wow lots of information i get here, starting from the 1st information until comment down here!

    Awesome!

    Even though my box is in good shape, all of the question just give me an idea to try more thing

    [Reply]

  21. Mehdi says:

    vesa;

    If you are using a DHCP to get your IP address then you just need to have a couple of lines in interfaces file;
    like this;

    auto eth0

    iface eth0 inet dhcp

    and of course the first line about your loopback, that stays the same (lo).

    also put a # sign in front of each line that you dont want, instead of deleting them so in case you need to use the same lines later.
    As always make backup copies before doing any thing (like in menu.lst file)

    [Reply]

  22. Mehdi says:

    Navid;

    sorry for late reply,
    I am not sure why you are getting this error;

    wmaster0: unknown hardware address type 801

    would it be that the wireless NIC is turned off or disabled?
    Or do you dual boot with Windows? because some times if using Windows the Power Save (in windows) puts the NIC in “sleep” mode and if you reboot in linux the NIC stays in the sleep mode (until windows brings it back) This is a known problem.
    sorry I dont have any wireless on my machine so I cannot tell you where exactly the problem is.

    you can always check the log files under /var/log/ they are really helpful.
    thanks

    [Reply]

  23. Mehdi says:

    Oh BTW for those who use your GUI to configure the Network,
    If you do both configurations in the GUI and in the command line as well, you will have problems with your network card, it for some reason goes disabled.
    It happened to my machine several timesĀ·(the check mark next to my NIC became a – sign?! in GUI while ifconfig said it was up)

    Also you have to put your DNS address and domain name in the file /etc/resolv.conf (also in interfaces).

    like in resolv.conf ;
    search (the name of your domain like your-isp.com)
    nameserver 192.168.1.1 (or whatever your router/dhcp server address is happened to be)

    and in your interfaces like;

    dns-nameservers 192.168.1.1
    dns-search your-isp.com

    it would not hurt to add DNS address of your ISP as well (if you know it), you dont have a limit to 1 address

    [Reply]

  24. naveed says:

    hi Mehdi,

    thanks for your help, i got internet by reinstalling ubuntu and re configure drivers.

    But few more questions, appreciate if you can answer.

    1) I bought 8 DBi ANTENNA Kit (for better coverage), but i don’t know how to configure as i am getting the same result as 2 DBi.

    2) I have install ubuntu on my laptop acer aspire 5920G which has got inbuilt wireless. i want to disable that inbuilt wireless and use alfa to get better internet strength.

    [Reply]

  25. Tuv says:

    Hello all,

    I am very new in ubuntu and tried to configure my network and input sudo /etc/network/intefaces. My question is, is there any key I need to press first before inputting the below lines:
    auto eth0
    iface eth0 inet dhcp

    It keeps on beeping when I input those lines above. Also, how do I save the above lines. I really need your help.

    Thanks a lot.

    [Reply]

  26. Tuv says:

    Sorry, i guess it is sudo vi /etc/network/intefaces.

    [Reply]

  27. Betsy says:

    Thanks for the very helpful info! I got the networking going from the shell thanks to this.

    [Reply]

  28. Shelby says:

    After I edit this file “/etc/network/interfaces”, how do I save the changes and exit the editor? I’m using vi.

    “vi /etc/network/interfaces

    [Reply]

Leave a Reply