Email This List Email This List Print This List Print This List

Con­fig­ure your Linux net­work inter­face

1. View Net­work Set­tings of an Eth­er­net Adapter

Ifcon­fig, when invoked with no argu­ments will dis­play all the details of cur­rently act­ive inter­faces. If you give the inter­face name as an argu­ment, the details of that spe­cif­ic inter­face will be dis­played.

# ifconfig eth0

eth0   Link encap:Ethernet  HWaddr 00:2D:32:3E:39:3B
inet addr:192.168.2.2  Bcast:192.168.2.255  Mask:255.255.255.0
inet6 addr: fe80::21d:92ff:fede:499b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:977839669 errors:0 dropped:1990 overruns:0 frame:0
TX packets:1116825094 errors:8 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2694625909 (2.5 GiB)  TX bytes:4106931617 (3.8 GiB)
Interrupt:185 Base address:0xdc00

2. Dis­play Details of All inter­faces Includ­ing Dis­abled Inter­faces

# ifconfig -a

3. Dis­able an Inter­face

# ifconfig eth0 down

4. Enable an Inter­face

# ifconfig eth0 up

5. Assign ip-address to an Inter­face

Assign 192.168.2.2 as the IP address for the inter­face eth0.

# ifconfig eth0 192.168.2.2


Change Sub­net mask of the inter­face eth0.

# ifconfig eth0 netmask 255.255.255.0


Change Broad­cast address of the inter­face eth0.

# ifconfig eth0 broadcast 192.168.2.255


Assign ip-address, net­mask and broad­cast at the same time to inter­face eht0.

# ifconfig eth0 192.168.2.2 netmask 255.255.255.0 broadcast 192.168.2.255

Altern­at­ively:

Edit /​etc/​hostname, enter:
# cat /etc/hostname
Sample ip con­fig:

 
server1.cyberciti.biz

Edit /​etc/​network/​interfaces, enter:
# cat /etc/network/interfaces
Sample stat­ic ip con­fig:

 
iface eth0 inet static
     address 192.168.1.10
     network 192.168.1.0
     netmask 255.255.255.0
     broadcast 192.168.1.255
     gateway 192.168.1.254

Edit /etc/resolv.conf and setup DNS serv­ers, enter:
# cat /etc/resolv.conf
Sample dns stat­ic IP con­fig­ur­a­tions:

 
search shineservers.com
nameserver 192.168.1.254
nameserver 8.8.8.8
nameserver 202.54.2.5

Finally, you need to restart the net­work­ing ser­vice under Debi­an /​ Ubuntu Linux, enter:
# /etc/init.d/networking restart

Type the fol­low­ing com­mands to veri­fy your new setup, enter:
# ifconfig eth0
# route -n
# ping google.com

6. Change MTU

This will change the Max­im­um trans­mis­sion unit (MTU) to XX. MTU is the max­im­um num­ber of oct­ets the inter­face is able to handle in one trans­ac­tion. For Eth­er­net the Max­im­um trans­mis­sion unit by default is 1500.

# ifconfig eth0 mtu XX

7. Promis­cu­ous mode

By default when a net­work card receives a pack­et, it checks wheth­er the pack­et belongs to itself. If not, the inter­face card nor­mally drops the pack­et. But in promis­cu­ous mode, the card doesn’t drop the pack­et. Instead, it will accept all the pack­ets which flows through the net­work card.


Super­user priv­ilege is required to set an inter­face in promis­cu­ous mode. Most net­work mon­it­or tools use the promis­cu­ous mode to cap­ture the pack­ets and to ana­lyze the net­work traffic.


Fol­low­ing will put the inter­face in promis­cu­ous mode.

# ifconfig eth0 promisc


Fol­low­ing will put the inter­face in nor­mal mode.

# ifconfig eth0 -promisc

Related Post

admin has written 133 articles