July 15, 2024

Network Configuration in Linux

This article covers TCP/IP networking, network administration, and system configuration basics. Linux can support multiple network devices. The device names are numbered and begin at zero and count upwards. For
example, a computer with two NICs will have two devices labeled eth0 and eth1

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

add or delAdd or delete a route
-host x.x.x.xAdd route to a single host identified by the IP address
-net x.x.x.xAdd route to a network identified by the network address
gw x.x.x.xSpecify the network gateway
netmask x.x.x.x Specify the network netmask
defaultAdd a default route


1. add route to a host $ route add -host x.x.x.x eth1
2. add route to a network $ route add -net netmask eth0
3. Alternatively, you could also use cidr format to add a route to network route add -net eth0
4. add default gateway $ route add default gw eth0
5. 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

add or del or change or append
or replace
Change a route
show or flushthe command displays the contents of the routing tables or remove it
restorerestore routing table information from stdin
getthis command gets a single route to a destination and prints its contents exactly as the kernel sees it


1. Set default gateway to $ ip route add default via
2. 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:

1. the remote system's IP address<ip_rem> ,
2. one or more blank spaces, and
3. the identifier <hostname>.

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 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

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
 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 a 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

That’s it, Hope, You will like it!!

Vedant Kumar

Currently I'm working as an Implementation Engineer, Started my career as an System Administrator - Linux. Additionally loves to explore new technologies and research about new open-source software that ease the development cycle.

View all posts by Vedant Kumar →

Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.


Ad Blocker Detected!

We've noticed that you are using an ad blocker. Advertising helps fund our server cost and keep it truly independent. It helps to build our content creator team. So please disable your ad blocker, and help us to keep providing you with free- great content - for free. Thank you for your support.