How to temporary configure network interfaces with iproute2

How to temporary configure network interfaces with iproute2

In this tutorial I will show you, how to temporary configure network interfaces with iproute2.

The ip command is newer and better than the old ifconfig. It displays the IP address, the netmask, the broadcast, the MAC address and other information.

The ip is better than ifconfig, for a number of reasons:

  • it works for IPv6
  • it can set multiple adresses on a network
  • it is more appropiate to the Network Oriented OS (like Cisco IOS or Juniper) commands.

The ip command can easily replace the ifconfig and route commands.

The ip command has non-interactive completion.  So, to view the IP addresses, for example you can use:

$ ip addr show
$ ip addr
$ ip a s
$ ip a

View network configuration with the ip command:

Display the network configuration for all the interfaces:

$ ip addr show
1: lo: mtu 16436 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: mtu 1500 qdisc pfifo_fast state UP ql en 1000
link/ether 00:0c:29:5d:83:c7 brd ff:ff:ff:ff:ff:ff
inet 192.168.8.181/24 brd 192.168.8.255 scope global eth0
inet6 fe80::20c:29ff:fe5d:83c7/64 scope link
valid_lft forever preferred_lft forever

Display the network configuration for a chosen interface:

$ ip a s eth0
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:5d:83:c7 brd ff:ff:ff:ff:ff:ff
inet 192.168.8.181/24 brd 192.168.8.255 scope global eth0
inet6 fe80::20c:29ff:fe5d:83c7/64 scope link
valid_lft forever preferred_lft forever

Display the routing table:

$ ip route show
default via 192.168.8.2 dev eth0
192.168.8.0/24 dev eth0 proto kernel scope link src 192.168.8.181

or: ip r s

Display the ARP table:

$ ip neigh show
192.168.8.1 dev eth0 lladdr 00:50:56:c0:00:08 REACHABLE
192.168.8.2 dev eth0 lladdr 00:50:56:f8:db:8f STALE
192.168.8.254 dev eth0 lladdr 00:50:56:ea:f9:8b STALE

or: ip n s

Temporary enable or disable a network interface:

Syntax: ip link set {up,down} dev interface_name

Enable eth0: ip link set up dev eth0
Disable eth0: ip link set down dev eth0

Set temporary IP and netmask:

I will set 192.168.1.100 as my IP and 24 (255.255.255.0) as netmask for eth0.

$ ip addr add 192.168.1.100/24 dev eth0

Netmask representation:

  • /8 is 255.0.0.0
  • /16 is 255.255.0.0
  • /24 is 255.255.255.0

Note: if you change the network configuration over ssh, the connect to the server will be lost.

Set temporary MAC address:

When you set the MAC address, make sure you have the network interface down.

$ ip link set down dev eth0
$ ip link set dev eth0 address AA:BB:CC:DD:EE:FF
$ ip link set up dev eth0

Add default route:

Syntax: ip route add default via GATEWAY_IP

$ ip route add default via 86.123.45.6

Temporary configure the routes:

Syntax: ip route add (network)/(mask) via (ip to route)

$ ip route add 1.2.3.4/16 via 86.123.45.6 dev eth0

Configure IP and default gateway for IPv6:

  • ip and mask: ip addr add 2002:aa:bb::100/64 dev eth0
  • route : ip -6 route add default via 2002:aa:bb::1 dev eth0

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!

 
Enjoyed this video?
How to temporary configure network interfaces with iproute2
"No Thanks. Please Close This Box!"