February 5, 2007 · Networking · Email This Post

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

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

# 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

# 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

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

enter the following details

search test.com
nameserver 192.168.3.2

  • Share/Save/Bookmark

Related Articles

75 Comments to “Ubuntu Networking Configuration Using Command Line”

  1. Betsy says:

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

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

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

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

  4. Tuv says:

    Shelby,

    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.

    Regards,
    Tuv

  5. Tuv says:

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

  6. Brian M says:

    Awesome post… keep up the good work.

    - B

  7. Rhyan D says:

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

    :(

  8. Matey says:

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

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

  10. Paul Yearron says:

    Hi,

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

    Thanks

    Paul.

  11. Paul Yearron says:

    Hi,

    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,

    Cheers

    Paul.

  12. Debasis Mohanty says:

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

  13. romal says:

    Hi everyone,
    I am working on a project for all the operative systems, but I didn’t use that much LINUX(Ubuntu) and I don;t have enough info. Could you help me solve these exercises since they are a part of my project.
    Here is a link of my exercises:

    http://www.speedyshare.com/553182178.html

    Procedure:
    write in a file the steps that you have used and the results that you are getting (you can do it in a photo too or anything that suits you best.

  14. kaithy aravind reddy says:

    Very good article to setup..Thanks

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

Leave a Reply