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

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
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


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 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

Sponsored Link

Related posts

You may also like...

140 Responses

  1. Shelby says:

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

    Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for “colon” commands which execute when you press the return key.

    😡 Exit, saving changes
    :q Exit as long as there have been no changes
    ZZ Exit and save changes if any have been made
    :q! Exit and ignore any changes

  2. Tuv says:


    Thanks for your informative response. I have done researched on the internet also and found more abuot vi editor. I setup my internet now and can download files. My problem now is, I have downloaded and installed ubuntu-desktop already and when I input startx, it says Fatal Server error: no screen found. Any ideas?..Anyway this can be not part of this thread anymore. I have read also from other thread that this can be on driver issue. Again, Thanks to you guyz. I start to love ubuntu now.


  3. Tuv says:

    More fun and challenging using ubuntu via command line. I learned a lot.

  4. Brian M says:

    Awesome post… keep up the good work.

    – B

  5. Rhyan D says:

    it works for me but i can’t access my http://localhost or or http://###.###.#.##


  6. Matey says:

    I think in order to have your localhost as a web page you have to run apache2 -k start

  7. This is interesting web place. I like it.

  8. Paul Yearron says:


    I am fairly new to SQUID and have followed the instructions above, have set my proxy server to be the IP address of the squid server with port 3128 but am unable to access the web.e.g. google.

    After a couple of minutes I get a message from the squid server saying that the requested URL cannot be found. connection to failed. I have verified that I can ping the above address from a command line on the Squid server.

    The server is running on an ESX 3i server. I am able to access the web console via the https:ip:10000 website.

    I think I may need to connect a second lan Connection from the ESX host to our DMZ and perhaps open a few ports on the firewall but not having much experience with SQUID I could be wrong.

    Any help greatly appreciated,



  9. Paul Yearron says:


    Quick update I have now managed to get a step further and am now getting the message
    Access Denied.
    Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.

    I have tried to look at the ACL list on the web browser but not really getting anywhere,



  10. Debasis Mohanty says:

    I can’t use my net (BORD BAND) in my Linuxe
    Ubunt 2

  11. kaithy aravind reddy says:

    Very good article to setup..Thanks

  12. Matey says:

    Paul Yearron;
    We use apache2 and there are .conf files like httpd ports. and apache2.conf which you can edit and set your PORT numbers there.
    I do not know Squid sorry and am new to linux but I have played with our webserver (without crashing it lol) and found out basically how the ports are set.

    we also use zope and plone which are simple to configure but hard to get them to come up right!!? I mean the conf files are in plain English but the program(s) depend on many other factors like having a real IP address from your ISP and also configuring the network via files under /etc and /etc/network/
    files such as resolv.conf interfaces.conf etc. etc.

  13. Mandy says:

    Very helpful. Thanks

  14. Matey says:

    Hey guys, if you are having problem getting IP address from your cable router/DHCP server run this command in terminal;

    also running ifconfig shows you the info about your network card(s) and their IP address(es).

    same thing if you do this in terminal (to renew IP);

    /etc/init.d/network restart

    If you use the terminal/command line to configure your network, it is a good idea NOT to use the GUI program at the same time because I have seen it conflict.
    use one or the other not both.
    Remember if you want to configure your wireless router,(for the 1st time) connect your computer to the router with a network cable, You cannot configure the wireless section of your router while on wireless.
    If you want to give a static IP to your NIC (suppose your network card is eth0) then this is the command

    ifconfig eth0 inet netmask

    of course you can add other command to it like mtu 1500 etc, and of course make sure that address does not already exist so there wont be a conflict.

  15. paul kingsley says:

    thanks for the information you are providing on this site. i want to know how to configure the mail server so that i can send mail in my local network. i am a new user of ubuntu os.

  16. seanearlyaug says:

    I have tried this and other site’s suggestions.
    They failed. They usually left me wondering what I was doing in Linux, and did not describe the windows stuff correctly, had no path for failure at any one point, did not consider the router. Usually all of the above.

    I still want to thank everyone here, much of the advice got me far, just not to the goal.

    It is now working. But I need some help with the way it is working. I detailed this in an email to a Unix guru who lacks wireless experience.


    > Yes, I do want to descrbe this, and may use this same description in a Linux forum.
    > I have had problems for weeks getting my network to work.
    > A brief description of the setup:
    > Gamer is a linux machine, a desk top, with both wired/cabled and wireless
    connections. and setup to boot to Linux with out a sign-on screen. Groupname is MSHOME
    > Seans Laptop is a Winxp macine, It can read DVDs, and the program I need to install
    on Gamer is on this machine’s CD ROM DVD drive. It boots w/o a password, and has both a
    cable and 2 wireless connections, one that is unreliable,
    > group name was MSHOME.
    > INSITE is Heather’s school machine, likely winxp, and need a password. Group name is
    MSHOME, I believe.
    > Fifi is Fiona’s laptop, XP, no password. Group name is FAMILY
    > All run through a Linksys router, and from there to the Fios cable.
    > My problem was I could (eventually) see the systems, but I coiuld not see the files
    on those systems.
    > I kept getting password requests and getting blown off.
    > Then Fifi was turned on, and I could see all the shared drives. Wonderful.
    > I changed the Sean’s Laptop’s group name to SEANLAP. No change.
    > I removed the cable to Sean’s Laptop. And got access to the shared drives. I put the
    cable back in, and lost access.
    > Very strange. Any idea what is happening?

    No idea. But some systems don’t like to have no password. Maybe you
    should try creating a password.

    >The system did not work when wired and wireless were both connected
    The system did work with just wireless.
    I do not think that it has much to do with passwords, excetpt that the symptom when it did
    not work was that it asked for a password.
    I have not tried removing Gamer’s cable, forcing it to go wireless.

  17. OLAMIPO says:

    I have 2 ubumtu linux desktop on my Network. other desktops had window xp installed on them. I have shared the hp 2015p printer for other computers but not the linus computers to print from this printer. how can i configure the linux desktops to print from this pinter. am very hew to ix.

  18. OLAMIPO says:

    I am very new to Linux.

  19. matey says:

    The printing config in Linux is really easy, if this printer is connected directly to your XP machine, (such as USB or Lpt1 connect.) the Linux uses the XP machine’s IP address, you should activate File and Printer Sharing in the XP with printer hooked up.
    If the printer has its own IP address (like it has a print server with an RJ45 connector in the back) then its really too easy just go to the System, Administration, Printing and it will find it for you.

  20. Ashim says:

    I am using bsnl wll connection in Jharkhand,India.
    When I install ubuntu 9.04 It ws so easy tom install the BSNL WLL connection.

    But now when i use 9.10 version it does not detect the device as in 9.04.

    When I manually configure the device It does not connect.

    Please help me…….

  21. ferry says:

    where i can get hierarki directory of lunux ubuntu 9.10
    please reply my message as soon as

  22. jasim says:

    I want to thank everyone here, much of the advice got me far,

  23. Mageda says:

    I want to make ad-hoc connection between two 9.10 ubuntu laptops using command line..

    but I’m having trouble doing that..
    I’m setting the mode then the channel then the essid after that the static IP, and When I ping the other IP, I get host unreachable.

    But what is the command to connect them?
    I really need help !!

  24. nik says:

    hey could someone help me get 2moons to work on ubuntu i have all system requirments for it heres a list i have all of this and above

    CPU: Pentium 4 2.4GHz or higher
    RAM: 1GB
    VGA: GeForce FX5900 128MB or higher
    Connection: DSL/Cable or greater

    but for driver requirments it asked for this

    ATI Driver
    nVidia Driver

    so tried installing direct x it didnt work on linux then i tried ati driver and it had a version for linux but it never worked so i tried nvidia and it also had a version for linux and i have it but my 2moons still doesnt work i played 2moons on my other computer that ran on windows xp but it crashed so my friend gave me his computer for free and it runs on ubuntu i cant get this to work please help i had no problems downloading 2moons i opened it on wine and updated it but when i click start its suposed to start the game but the screen just disapears and i didnt know what to do i thought it might of been a problem with the driver requirments thing but i dont know what to do i went on youtube and someone had a video of them playing 2moons on ubuntu
    please help i just want it to work i invested 2 days straight trying to fix it so im comeing to you guys

  25. adr says:

    Hi! I am trying to configure the network and all the options of the window appear disabled. What can i do?

  26. jasim says:

    Its Great,


  27. ahmed says:

    Is Linksys Router supports static IP with Verechul IP or no
    Please reply to the necessary high e-mail

  28. Mate says:

    Yes most of the Linksys routers I have worked with do support both static and dynamic IPs. you can reserve addresses at the DHCP (that creates dynamic IP) part of the router. like specify the range from 192.168.1 to 20 for static Ip the rest for dynamic. this comes in handy like when you have a printer and you want to assign a static IP to it.

  29. rduke15 says:

    When will this vi insanity stop?

    90% of the Linux help I come across on the Internet seems to imply that vi has to be used when a text file needs to be edited. vi is a very special text editor, and is totally inappropriate for casual editing of a configuration file by non-expert users. The suggestion of vi is probably also the main reason why there are voices complaining about one the greatest usability features of Linux: the fact that configuration is generally done in plain text files. This is a huge advantage, but if beginners get the impression that they need to use vi to change a configuration setting, i guess most immediately abandon. And if the prefer regedit.exe to vi, I can understand them.

    This page was talking about Ubuntu. It comes with gedit by default, which is one of the many normal text editors anyone can use. And there are plenty of other fine text editors for Linux which are suitable for beginners (nano or mcedit in the console (part of mc); kate, geany, etc. in the GUI)

    So please replace vi by gedit in this page and let beginners concentrate on what they are trying to achieve, instead of needing to learn some crazy vi modes.

    perl -i.bak -pe ‘s/\bvi\b/gedit/g’ ubuntu-networking-configuration-using-command-line.html

  30. Teddybear says:

    [email protected]:~$ sudo /etc/init.d/networking restart
    * Reconfiguring network interfaces… SIOCADDRT: No such process
    Failed to bring up eth0.

    What should i do? ifconfig shows that the ip’s have been modified and also the MAC, but the networking restart just won’t work. I also modified the resolve.conf, still no luck. Can someone help? Thanks!

Leave a Reply

Your email address will not be published.