ip Commands

network

Configure IP Address and routing using the ip command.

How to assign a IP address to an interface

The following command will assign an IP address to a specific interface.

# ip addr add 192.168.50.11/24 dev enp2s0

How to check an IP address

To get information of the network interfaces like IP and MAC address, use the following.

# ip addr show
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
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether d0:50:99:48:8f:10 brd ff:ff:ff:ff:ff:ff
    inet 192.168.50.11/24 brd 192.168.50.255 scope global dynamic enp2s0
       valid_lft 6872sec preferred_lft 6872sec
    inet6 fe80::d250:99ff:fe48:8f10/64 scope link
       valid_lft forever preferred_lft forever

How to Remove an IP address

The following will remove an assigned IP address from the given interface (enp2s0).

# ip addr del 192.168.50.11/24 dev enp2s0

How to Enable Network Interface

The up flag with interface name enables a network interface. For example, the following command will activates the enp2s0 network interface.

# ip link set enp2s0 up

How to Disable Network Interface

The down flag with interface name disables a network interface. For example, the following command will De-activates the eth1 network interface.

# ip link set enp2s0 down

How do I Check Route Table?

Type the following command to check the routing table information of system.

# ip route show
default via 192.168.50.254 dev enp2s0  proto static  metric 100
192.168.50.0/24 dev enp2s0  proto kernel  scope link  src 192.168.50.11  metric 100

How to add a Default Gateway

You can add a default gateway with the following command.

# ip route add default via 192.168.50.254

Refer to the manual page for more information.

Previous Post Next Post