Ubuntu Networking Configuration Using Command Line
Sponsored Link
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
mr amit first u can disable firewall and also disable ipv6 then after u can access internet
After restart all IP setting are flushing.
Pls help me..
how to configure dual lan in UBUNTU ??
What is the broadcast address for?
it is an address, which covers all addresses in the subnetwork, I think
Ok this is all well and good but completely useless for my problem as /etc/resolv.config is a TEMPORARY file and gets overwritten each time the computer is rebooted. Having to edit that file every timeI boot the machine up is getting old fast. So where do I go to permanently add the infor that I keep adding to /etc/resolve.config using command line?
Change the file access permissions to only read for your user.
And how does that answer my question?
Use /etc/resolv.conf instead of /etc/resolv.config
Ubuntu uses a resolver setup called resolvconf which I find difficult to follow. You could start with man : me@home:~$man resolvconf.
Online at ubuntu there is a set of man pages too, for example if you use karmic then:
http://manpages.ubuntu.com/manpages/karmic/man8/resolvconf.8.html
I wish you luck in trying to figure it out !
I have read the man again. It seems to me that there are only two scenarios: IP address obtained from DHCP server, or IP statically set.
For IP address obtained from DHCP server you must set the DNS server entries in the DHCP server e.g. your internet router. DHCP will pass this to your desktop pc, which will tell resolvconf to update it’s information. /etc/resolv.conf is just a link to the resolvconf configuration : there is no need to touch it. Now you have your DNS set up, the same as your router.
Scenario 2: you are behind a router but have a static IP address. In this case you must include a line in /etc/network/interface to set the DNS server information. Your networking software will push this to resolvconf which will update the DNS record to use your choice of DNS server. Here is an example of an entry in /etc/network/interfaces:
## The primary network interface — use fixed IP settings
#
# 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
## This dns entry will push information to resolvconf.
## /etc/resolv.conf gets the info as it is
## a link to the resolvconf setup file.
# dns-nameservers 11.22.33.44 55.66.77.88
# After any changes, restart networking using
# sudo /etc/init.d/networking restart
Change the entry to suit your setup.
Finally note you must restart networking as last line in example.
I am not a guru so read first e.g. use google and search for ‘ubuntu resolvconf’
The above example just adds the dns-nameservers line to the example given earlier in this article, sorry I meant to credit this in my previous post.
Thanks for the post. For some reason my network was configured to the loopback device. My ssh logins and other network connection are much faster now.
Hi,
I cant able to ping google.com I had given DNS but it is not working. Help me
How do I change my /etc/network/network file to read-write? I’m not able to change it.
Thanks.
I’m a newbe.
I am running Ubuntu 12.10
How would I just view the settings for my network. I can bet it is a cat command but not exactly sure where/how to find it on the command line. I would normally just do an ipconfig in windows. Any help would be grateful
Thanks
ifconfig is probably what you’re looking for. Read the man page if you need more specifics than what it gives you by default.
Bill, not sure if you figured it out, but you should be able to do the following command:
sudo chmod 644 /etc/network/network
HTH
I am a newbie in Ubuntu….
Do I always need to get package index from the internet ?
And .. is it able to install Windows Program and Software in Ubuntu ?
If I don’t want them ‘ how can I remove ?
Can I play Dota 2 on Ubuntu ?
Hi
I cant able to ping google.com I had given DNS but it is not working