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
@ rduke15
you have no idea how much you helped by the gedit instead of vi tip.
thanks a lot
Or replace vi with nano, for everyone coming from windows, the simple and intuitive nano editor is a heaven sent…!
Hey, could you post the default loopback part of the network config?
I deleted it accidentily and am unsure how to get it back. It was simply two lines of code something like
auto lo inet an_ip_maybe?
iface lo something something
Much appreciated. Thanks
# The loopback network interface
auto lo
iface lo inet loopback
any one know,how to set load balancing in linux?
I’m trying to add a second nic without re-install, need it to use heartbeat, I have latest lucid server that was an upgrade from 9.10..does not detect the nic though..any help appreciated!
Thanks. This tutorial very good.
i have a lap and dekstop. both ubuntu 9.10. how to share files? i have cross crimbed network cable. any help in this matter?
i just try ubuntu 9.10 server. i want to know
1. How do i know that the lan card is installed?
2. if there are more than one lan card, how do i now the interface number of the cards?
Run the following command from your terminal and see the output
ifconfig
as far as i know ifconfig doesn’t inform the type of lan card.
if i have 3 lan cards, i need to know which one is eth0, eth1, and eth3.
Thanks. Useful help for me>
Once you add the two lines of code, how do you save?
I think it would be the esc key then shift :w to write, then esc shift :q! to exit out? using vi.
jus smak me if im wrong..lol
p.s.
for go..sake, backup the orig!
Jack;
If you have pico (or nano) you can edit and then save by Ctrl X (to exit) then press Y for yes.
if you are using vi (which I know very little about) do as Josh said above. Also you can do shift ZZ to exit vi.
as already said, good idea to save a copy first. like
cp file.1 file.2
then
pico file.1
if anyone else knows of another cool editor let us know please.(I assume that ppl are using command line or terminal & not GUI or X).
this is good but i tried same like this but my network is not configured.ip address cant accept it.help me
Biswajit;
are you using wireless or wired network?
has linux found your network card?
are you using xwindows or command line?
do you have access to your router/dhcp server (is this at home or at work)?
did you run the ifconfig -a and see what it says?
+1 to rduke15 for point out the insanity of using vi instead of the much simpler gedit to edit /etc/network/interfaces file.
unless you installed Ubuntu to not use X graphical interface, there is no reason to use vi.
USE gedit
Thanks to Joe for publishing the default loopback interface, sorry for the late thanks.
And to ieee488, the poster actually says ‘Note :- Use vi editor if you donβt have GUI installed;’
So your statement is rendered pointless.
To Check How many Network Interface Cards Install, execute the following command,
[email protected]:~$ ifconfig
Note: if numbers of network card installed then it recognized as eth0, eth1, eth2, . . . in Linux
nice tuts!!! now i have alias π
Now that we have two “interfaces” and two ip.
How can we force a program to use only one interface ?
I can set QoS and operational time on my router per IP. So, for example, I can define low bandwidth during the day for that specific IP in my LAN.
I would like to force a specific program to use only one IP and all other applications use the the other one.
Thanks
ps vi is extremely efficient and fast compared to gedit. I admit that you have to get use to it.
Ubuntu is cool π Very nice collection of Terminal commands π
am new in ubuntu server, pliz help me with configuration comands
nano is a good editor and is built in ubuntu too. it also has command helpers on the bottom.
I want to ask if how to detect/configure the NIC if I installed ubuntu on a virtual machine? I set up Bridged Adapter and/or Host-only adapter but still does not show up when I type ‘ifconfig’.
I also modified the /etc/network/interfaces file.
I am trying to configure my ubuntu machine as a firewall. It has two NICs, one for internet (eth0) and other for LAN (eth1). I connected internet cable to etho and my laptop to eth1 using crossover cable.
I am able to access ubuntu machine from laptop but unable to access internet. I user iptables to forward traffic from eth1 to eth0. But it is not working.
Please suggest.
i have a missing cd od wireless pci
adapter anyone knows how to find the software?
it says 300mbps but it doesnt go up to 300mbps
Its simple to save any file ,just press Esc key and type:wq