IP Commands to Configure Network Interfaces

IP Command to Configure Network Interfaces

In this tutorial we will discuss about Configuring Static IP Address Internet Protocol (IPv4). In order to assign Static IP Address, you need to update or edit network configuration file. Using IP command, set IP address without update or edit network configuration file.

Assign IP Address to Specific Interface

Run the following commands to assign IP address to a specific interface using ip command.

[root@linuxhelp Desktop]# ip addr add 192.168.5.82 dev eth0

All the settings will be lost when you reboot your system.

Command to check ip address

The following ip commands provide you with more information of your network interfaces like MAC Address information and IP Address.
You can use any of these two command as shown below.

[root@linuxhelp Desktop]# ip addr show

or

[root@linuxhelp Desktop]# ip a 
1: lo: < LOOPBACK,UP,LOWER_UP>  mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: < BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:dd:23:8c brd ff:ff:ff:ff:ff:ff
inet 192.168.5.82/24 brd 192.168.5.255 scope global eth0
inet6 fe80::20c:29ff:fedd:238c/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: < BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc noqueue state UNKNOWN
link/ether 52:54:00:86:7c:3d brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
4: virbr0-nic: < BROADCAST,MULTICAST>  mtu 1500 qdisc noop state DOWN qlen 500
link/ether 52:54:00:86:7c:3d brd ff:ff:ff:ff:ff:ff

Command to remove the IP address

The following ip command will remove an assigned IP address from the given interface.

[root@linuxhelp Desktop]# ip addr del 192.168.5.82 dev eth0

After removed ip address you can verify the status by below command.

[root@linuxhelp songs]# ip a
eth0: < BROADCAST,MULTICAST>  mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:dd:23:8c brd ff:ff:ff:ff:ff:ff

Command to Enable Network Interface

The flag, up with the interface name eth0 enables a network interface.

[root@linuxhelp Desktop]# ip link set eth0 up

After enabled network interface you can verify the status by below command.

[root@linuxhelp Desktop]# ip a
eth0: < BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:10:e1:fd brd ff:ff:ff:ff:ff:ff
inet 192.168.5.82/24 scope global eth0
inet6 fe80::20c:29ff:fe10:e1fd/64 scope link
valid_lft forever preferred_lft forever

Command to Disable Network Interface

The flag, down with interface name eth1 disables a network interface.

[root@linuxhelp Desktop]# ip link set eth0 down

After disabled network interface you can verify the status by below command.

[root@linuxhelp Desktop]# ip a
eth0: < BROADCAST,MULTICAST>  mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:dd:23:8c brd ff:ff:ff:ff:ff:ff
inet 192.168.5.82/24 scope global eth0

Command to Check the Route Table information

The following ip command checks the information in routing table

[root@linuxhelp Desktop]# ip route show
192.168.5.0/24 dev eth0 proto kernel scope link src 192.168.5.82 metric 1
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
default via 192.168.5.1 dev eth0 proto static

Command to Adding Static Route

Generally static routes are added to pass traffic from the best way to reach the proper destination.

[root@linuxhelp Desktop]# ip route add 192.168.5.90 via 192.168.5.1 dev eth0

Command to Removing Static Route

Type the following ip command to remove the assigned static route.

[root@linuxhelp Desktop]# ip route del 192.168.5.90

Adding a permanent Static Routes

If you would like to add permanent Static route, then edit file /etc/sysconfig/network-scripts/route-eth0 and add the following command lines, save and exit.

[root@linuxhelp Desktop]# ip route del 192.168.5.90

Now restart your network services after assigned static routes in configuration file.

[root@linuxhelp Desktop]# service network restart

Adding a permanent IP address

If you want to add permanent ip address you should configure at the following path /etc/sysconfig/network-scripts/ifcfs-eth0, now your ip address assigned permanently.

[root@linuxhelp Desktop]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:DD:23:8C
TYPE=Ethernet
UUID=6576f85b-e6f5-42aa-bed3-fb207ab86ba1
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.160.5.82
NETMASK=255.255.255.0
GATEWAY=192.160.5.1
DNS1=8.8.8.8

Now restart your network services after assigned IP in configuration file.

[root@linuxhelp Desktop]# service network restart
Tag : ip command
FAQ
Q
How to Assign an IP Address to Specific Interface in Linux?
A
You can use the command to Assign an IP Address to Specific Interface in Linux. For Syntax: "ip addr add 192.168.50.5 dev eth1"
Q
How to Check an IP Address for a certain interface?
A
You can use the command to Check an IP Address for a certain interface. For Syntax: " ip addr show"
Q
How to Remove an IP Address for any certain interface in Linux?
A
You can use the following command to Remove an IP Address for any certain interface in Linux. For Syntax: " IP address del 192.168.50.5/24 dev eth1".
Q
How to Enable Network Interface in Linux?
A
You can use the following syntax to Enable Network Interface in Linux. For Ex: "ip link set eth1 up".
Q
How do I Check Route Table using the "ip" command in Linux?
A
You can use the following command to Check Route Table using the "ip" command in Linux. For Syntax: " ip route show".