Professional Documents
Culture Documents
10 Useful - IP - Commands To Configure Network Interfaces
10 Useful - IP - Commands To Configure Network Interfaces
Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators | 4 Free Shell Scripting eBooks
In this post, we are going to review how we can assign Static IP Address, Static Route, Default Gateway etc.
Assigning IP Address on demand using IP command. IFCONFIG command is deprecated and replaced
by IP command in Linux. However, IFCONFIG command is still works and available for most of the Linux
distributions.
10 IP Command Examples
Note: Please take configuration file backup before doing any changes.
For RHEL/CentOS/Fedora
Open and edit network configuration file for (eth0 or eth1) using your favorite editor. For example, to assigning
IP Address to eth0 interface as follows.
https://www.tecmint.com/ip-command-examples/ 1/6
17/12/2019 10 Useful "IP" Commands to Configure Network Interfaces
Simple output:
DEVICE="eth0"
BOOTPROTO=static
ONBOOT=yes
TYPE="Ethernet"
IPADDR=192.168.50.2
NAME="System eth0"
HWADDR=00:0C:29:28:FD:4C
GATEWAY=192.168.50.1
Assign Static IP Address to eth0 interface editing configuration file /etc/network/interfaces to make permanent
changes as shown below.
auto eth0
iface eth0 inet static
address 192.168.50.2
netmask 255.255.255.0
gateway 192.168.50.1
Next, restart network services after entering all the details using the following command.
# /etc/init.d/networking restart
https://www.tecmint.com/ip-command-examples/ 2/6
17/12/2019 10 Useful "IP" Commands to Configure Network Interfaces
Note: Unfortunately all these settings will be lost after a system restart.
# ip addr show
Sample Output
https://www.tecmint.com/ip-command-examples/ 3/6
17/12/2019 10 Useful "IP" Commands to Configure Network Interfaces
# ip route show
https://www.tecmint.com/ip-command-examples/ 4/6
17/12/2019 10 Useful "IP" Commands to Configure Network Interfaces
Sample Output
and save and exist. By default route-eth0file will not be there, need to be created.
For RHEL/CentOS/Fedora
# vi /etc/sysconfig/network-scripts/route-eth0
10.10.20.0/24 via 192.168.50.100 dev eth0
$ sudo vi /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.50.2
netmask 255.255.255.0
gateway 192.168.50.100
#########{Static Route}###########
up ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0
Next, restart network services after entering all the details using the following command.
# /etc/init.d/network restart
https://www.tecmint.com/ip-command-examples/ 6/6