Adel ALLAM @apges01

iproute2

ip is from iproute2 package.


show configuration


# addr
$ ip addr show
$ ip addr show eth0

# multicast addr
$ ip maddr

# link
$ ip link show
$ ip link show eth0

# other link info
$ ethtool eth0

# route
$ ip route show

# neighbors
$ ip neighbor

# multicast group of host
$ ip maddress show

# windows
$ arp -a
$ ipconfig
$ route print

configure


# clean interface
$ ip addr flush dev eth0

# addr
$ ip addr add 172.16.0.1/24 dev eth0

# up/down interface
$ ip link set dev eth0 up
$ ip link set dev eth0 down

# route
$ ip route add default via 192.168.0.254
$ ip route add 10.0.0.0/24 via 193.233.7.65

# promiscuous mode: pass all traffic to host rather
# than filter on destination address of NIC
$ ip link set dev eth0 promisc on

# mtu
$ ip link set dev eth0 mtu 1500

enable routing on Linux


# show
$ sysctl net.ipv4.ip_forward

# edit
$ sysctl net.ipv4.ip_forward=1

# for persistent rules add this in /etc/sysctl.conf
$ net.ipv4.ip_forward = 1

# apply changes
$ sysctl -p /etc/sysctl.conf

# old method
$ echo 1 > /proc/sys/net/ipv4/ip_forward

cli configuration


$ ip addr flush dev eth0
$ ip addr show dev eth0 # check

$ ip addr add 192.168.42.57/24 brd + dev eth0
$ ip addr show dev eth0 # check

$ ip route add default via 192.168.42.254
$ ip route # check

# test routing and find output interface
$ ip route get 164.81.1.4
164.81.1.4 via 192.168.42.254 dev eth0 src 192.168.42.57

# dhcp: interfaces + /etc/resolv.conf + default route
$ dhclient eth0

# dns config
$ vim /etc/resolv.conf
nameserver 9.9.9.9

file configuration


$ more /etc/network/interfaces

auto lo # start at boot
iface lo inet loopback

auto eth0 # start at boot
iface eth0 inet static # static config.
    address 192.168.42.57
    netmask 255.255.255.0
    gateway 192.168.42.254

auto eth1 # start at boot
iface eth1 inet dhcp # automatic config.

# restart service
$ systemctl restart networking

old commands


# show config.
$ ifconfig -a

# up/down interface
$ ifconfig eth0 up
$ ifconfig eth0 down

# config. ip
$ ifconfig eth0 192.168.1.1/24

# delete ip
$ ifconfig eth0 0.0.0.0/0

# interface dhcp, ip + gateway + dns + ...
$ dhclient eth0 

# routing table
$ route

# add gateway
$ route add default gw 192.168.1.254 eth0

# add network route
$ route add -net 172.16.10.10/24 gw 192.168.1.254

# add host route
$ route add -host 98.76.54.32 gw 12.34.56.1