# Network Configuration

# Interface details


List all the interfaces available on the machine

$ ifconfig -a

List the details of a specific interface

Syntax: $ ifconfig <interface>


$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:x.x.x.x  Bcast:x.x.x.x  Mask:x.x.x.x
          inet6 addr: xxxx::xxx:xxxx:xxxx:xxxx/64 Scope:Link
          RX packets:4426618 errors:0 dropped:1124 overruns:0 frame:0
          TX packets:189171 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:382611580 (382.6 MB)  TX bytes:36923665 (36.9 MB)
          Interrupt:16 Memory:fb5e0000-fb600000 

Ethtool - query the network driver and hardware settings

Syntax: $ ethtool <interface>


$ ethtool eth0
Settings for eth0:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    Speed: 1000Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 1
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: on (auto)
    Supports Wake-on: pumbg
    Wake-on: g
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: yes

ip - show / manipulate routing, devices, policy routing and tunnels

Syntax: $ ip { link | ... | route | macsec } (please see man ip for full list of objects)


List network interfaces

$ ip link show    

Rename interface eth0 to wan

$ ip link set dev eth0 name wan    

Bring interface eth0 up (or down)

$ ip link set dev eth0 up    

List addresses for interfaces

$ ip addr show    

Add (or del) ip and mask (

$ ip addr add brd + dev eth0 

# Adding IP to an interface

An IP address to an interface could be obtained via DHCP or Static assignment

DHCP If you are connected to a network with a DHCP server running, dhclient command can get an IP address for your interface

$ dhclient <interface>

or alternatively, you could make a change to the /etc/network/interfaces file for the interface to be brought up on boot and obtain DHCP IP

auto eth0
iface eth0 inet dhcp

Static configuration(Permanent Change) using /etc/network/interfaces file

If you want to statically configure the interface settings(permanent change), you could do so in the /etc/network/interfaces file.


auto eth0 # Bring up the interface on boot
iface eth0 inet static 

These changes persist even after system reboot.

Static configuration(Temporary change) using ifconfig utility

A static IP address could be added to an interface using the ifconfig utility as follows

$ ifconfig <interface> <ip-address>/<mask> up


$ ifconfig eth0 up

# Local DNS resolution

File: /etc/hosts contains a list of hosts that are to be resolved locally(not by DNS)

Sample contents of the file:         your-node-name.your-domain.com  localhost.localdomain  localhost 
XXX.XXX.XXX.XXX   node-name

The file format for the hosts file is specified by RFC 952

# Configure DNS servers for domain name resolution

File: /etc/resolv.conf contains a list of DNS servers for domain name resolution

Sample contents of the file:

nameserver # IP address of the primary name server
nameserver # IP address of the secondary name server

In case internal DNS server you can validate if this server resolve DNS names properly using dig command:

$ dig google.com @your.dns.server.com +short

# See and manipulate routes

# Manipulate the IP routing table using route

Display routing table

$ route # Displays list or routes and also resolves host names
$ route -n # Displays list of routes without resolving host names for faster results

Add/Delete route

Option Description
add or del Add or delete a route
-host x.x.x.x Add route to a single host identified by the IP address
-net x.x.x.x Add route to a network identified by the network address
gw x.x.x.x Specify the network gateway
netmask x.x.x.x Specify the network netmask
default Add a default route


  • add route to a host $ route add -host x.x.x.x eth1
  • add route to a network $ route add -net netmask eth0
  • Alternatively, you could also use cidr format to add a route to network route add -net eth0
  • add default gateway $ route add default gw eth0
  • delete a route $ route del -net

# Manipulate the IP routing table using ip

Display routing table

$ ip route show # List routing table

Add/Delete route

Option Description
add or del or change or append or replace Change a route
show or flush the command displays the contents of the routing tables or remove it
restore restore routing table information from stdin
get this command gets a single route to a destination and prints its contents exactly as the kernel sees it


  • Set default gateway to $ ip route add default via
  • Adds a default route (for all addresses) via the local gateway that can be reached on device eth0 $ ip route add default via dev eth0

# Configure a hostname for some other system on your network

You can configure your Linux (or macOS) system in order to tie in an identifier <hostname> to some other system's IP address in your network. You can configure it:

  • Systemwide. You should modify the **/etc/hosts** file. You just have to add to that file a new line containing:
      - the remote system's IP address ``, - one or more blank spaces, and - the identifier ``.
  • For a single user. You should modify the **~/.hosts** file --- you-d have to create it. It is not as simple as for systemwide. [Here](http://unix.stackexchange.com/questions/10438/can-i-create-a-user-specific-hosts-file-to-complement-etc-hosts) you can see an explanation.
  • For instance, you could add this line using the cat Unix tool. Suppose that you want to make a ping to a PC in yout local network whose IP address is and you want to refer to that IP address just by remote_pc. Then you must write on your shell:

    $ sudo cat remote_pc

    Then you can make that ping just by:

    $ ping remote_pc