Linux - Network                                 Home : www.sharetechnote.com

 

 

 

In this page, I will show you the ways to get the configuration information on NIC (Network Interface Card) and configure it as you like.  This is based on my try on Ubuntu.

 

 

 

View the current  NIC configuration - the command ifconfig

 

Example : # ifconfig

 

Example : # ifconfig eth0

    eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig'

 

 

 

View the current NIC configuration - the command ip  

 

Example : # ip addr

 

Example : # ip addr show

 

Example : # ip addr show eth0

    eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ip''

 

 

 

Assign an IP address for a network interface card (NIC)

 

Example : # ifconfig eth0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 up

    eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig'

    192.168.1.2 : IP address to be assigned for the NIC

    netmask 255.255.255.0 : set subnet mask to be 255.255.255.0

    up : This is not mandatory, but I recommend this to make it sure that NIC is enabled after this command

 

 

 

Enable an IP address for a network interface card (NIC)

 

Example : # ifconfig eth0 up

    eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig'

 

 

 

Disable an IP address for a network interface card (NIC)

 

Example : # ifconfig eth0 down

    eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig'

 

 

 

Adding IP address (Temporay) to a Network Interface Card (NIC)

 

Example : # sudo ip addr add 192.168.1.100/24 dev eth0

 

Example : # sudo ip addr add 192.168.1.100/24 dev eth0 label eth0:1  

    eth0 : Network Interface Card Name (you can figure out this name for your PC by 'IP' command

NOTE : You can check the result of this command using 'ip addr'.

NOTE : The IP added by this method will be disappear if you reboot the pc.

 

 

 

Deleting IP address (Temporay) from a Network Interface Card (NIC)

 

Example : # sudo ip addr del 192.168.1.100 dev eth0

    eth0 : Network Interface Card Name (you can figure out this name for your PC by 'IP' command

 

 

 

Adding a IP address (Permanent) to a Network Interface Card (NIC)

 

This is a little bit complicated. A single command would not do this. You need to change the contents of a interface configuration file as shown in the following example.

 

Open up the file named 'interfaces' located in '/etc/network' (i.e, open up the file /etc/network/interfaces) using text editor and add following lines and reboot the PC

    auto eth0:1

    iface eth0:1 inet static

    address 192.168.1.100

    gateway 192.168.1.254

    netmask 255.255.255.0

    eth0:1 => this is an alias for the NIC (a kind of virtual NIC) to which this IP will be assigned.

 

 

 

Adding the default Gateway to a network interface card(NIC)

 

Example : # route add default gw 192.168.0.1 wlan0

 

After this, you can confirm the default gateway options using 'ip route' command as below.

 

# ip route

default via 192.168.0.1 dev wlan0

default via 192.168.1.254 dev eth0 onlink linkdown

192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.28

192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 linkdown

 

 

 

Changing MTU

 

Example : # ifconfig eth0 mtu 1500

    eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig'

    mtu 1500 : set mtu to be 1500

 

 

 

Promiscuous Mode

 

Example (Enable the promiscuous mode) : # ifconfig eth0 promisc

 

Example (Disable the promiscuous mode) : # ifconfig eth0 -promisc

 

 

 

Allowing Wireshark to capture packets

 

Sometimes you would see the error message on Wireshark saying "You didn't specify on which to capture packets".

Then you may open "Capture" dialog and try to select "Interface",but don't see any interface name in it. In this case, you may try following.

 

Example : # setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/bin/dumpcap