Using the Linux iproute2 "ip" tool
Posted on August 24, 2013 at 9:00 PM by pcoutin
How to ip
This post is an overview of how to use the ip(8) tool for manually (and temporarily) configuring networking and getting information.
Show network status, network interface names
ip: (ip a
is an abbreviation, see ip-address(8)
)
# 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
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:44:02:42:42:42 brd ff:ff:ff:ff:ff:ff
# ip a show dev eth0
1: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:44:02:42:42:42 brd ff:ff:ff:ff:ff:ff
ip a
and ip li
both show slightly different network interface statuses.
Set IP address
First, flush any assigned IP addresses if necessary. Then add one:
Add IP address
Using ip a
(see ip-address
man page).
# ip a add 10.0.0.1/24 dev eth0
This adds or assigns the address 10.0.0.1 to interface eth0, with the netmask 255.255.255.0. The following also works:
# ip a add 10.0.0.1 netmask 255.255.255.0 broadcast 10.0.0.255 dev eth0
Remove assigned IP addresses
Remove all from eth0 interface:
# ip a flush dev eth0
Remove one:
# ip a del 10.0.0.1/24 dev eth0
Changing/spoofing MAC address of a network interface
Spoofing a MAC address might confuse certain things, making them think your device is a different device. It may allow you to do certain nefarious things.
From ip-link(8)
(type man 8 ip-link
on a command line to see the manual)
# ip li set eth0 down
# ip li set eth0 addr 00:de:ad:be:ef:42
# ip li set eth0 up
Note that you can use ip li set DEVICE
or ip li set dev DEVICE
. The dev
is omitted above to reduce typing.
Show routes/gateway/router
see ip-route(8)
# ip r
Set default gateway/router to 10.0.0.1
# ip r add default via 10.0.0.1
or
# ip r add default via 10.0.0.1 dev eth0
/etc/resolv.conf
This file holds DNS resolution configuration in most Unix-like operating systems.
To sell your soul to the evil Google overlords:
# echo "nameserver 8.8.8.8" > /etc/resolv.conf
This would make 8.8.8.8, Google’s public DNS server, be the main DNS resolver for the machine.
Show ARP cache
See ip-neighbour(8).
# ip neigh
# arp