ip

Link / Interface

ip -d link show eth0.8
ip link show eno1
 
ip link set eth0 up
ip link set dev <interface> up
ip link set dev <interface> down
 
ip link del docker0
 
# shutdown interface
ip addr del 10.0.0.2/24 dev eth0
ip link set eth0 down
 
# Configure VLAN
ip link add link eth0 name eth0.100  type vlan id 100
 
# show VLAN
ip -d link show
 
# Delete virtual interface
ip link delete qvb333c3ed4-51

Address

ip addr show eth0
 
ip addr add 192.168.1.33/24 dev eth0
ip addr add 192.168.0.111/24 dev eth0:1
 
# remove ip
ip addr del 10.22.30.44/16 dev eth0
ip addr flush dev eth0
 
# output as json
ip -j a | jq
ip -o -4 -j a show eth0 | jq -r .[].addr_info[].local

MTU
https://www.networkworld.com/article/2224654/mtu-size-issues.html

ip ad | grep mtu
ip link set dev eth0 mtu 1400
ip l set mtu 1200 dev wlan0

ifconfig
https://p5r.uk/blog/2010/ifconfig-ip-comparison.html

ifconfig -a
ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up
route add default gw 192.168.1.1
echo "nameserver 8.8.8.8" > /etc/resolv.conf

Route

ip route show default 0.0.0.0/0
 
sudo ip route del default
sudo ip route add default via 192.168.1.254
sudo ip route add 10.0.3.123 dev tun0 scope link
sudo ip route add 10.23.0.0/16 via $(getent hosts vpn.example.com | cut -d" " -f1)
ip r add ${NET} via ${GW} dev ${DEV} onlink
 
# route
#dep# sudo route add -net 192.168.254.0 gw 192.168.1.34 netmask 255.255.255.0 dev tap0
sudo brctl addbr br10
sudo ip link set dev br10 up
sudo ip route add 192.168.33.0/24 via 10.0.3.100 dev lxcbr0
 
# block route to
iptables -A OUTPUT -d 10.0.1.15 -j DROP
 
# block route without iptables
ip route add prohibit 10.0.1.15/32
 
# test (two routing tables)
echo "1 admin" >> /etc/iproute2/rt_tables
echo "2 users" >> /etc/iproute2/rt_tables
ip rule add from 192.168.122.40/32 dev eth0 table admin
ip rule add from 192.168.123.41/32 dev eth1 table users
ip route add default via 192.168.122.1 dev eth0 table admin
ip route add default via 192.168.123.1 dev eth1 table users
 
ip -4 route get 8.8.8.8
 
# show routing table
ip route

Bridge
http://panticz.de/brctl

# remove bridge
ip link set dev br10 down
brctl delbr br10
 
# delete interface
ip link delete br0

Bridge

apt install -y bridge-utils
brctl addif br0 enp0s8
ip addr flush dev enp0s8
ip link set br0 up
dhclient br0

Namespaces
https://unix.stackexchange.com/questions/210982/bind-unix-program-to-specific-network-interface

ip netns ls
ip netns exec qrouter-1111-2222-3333-4444-5555 ip a
ip netns pids qdhcp-1111-222-333-444-555-6666 | xargs ps -o pid,command -p
 
# find IP in namespaces
IP=172.16.100
for NS in $(ip netns | cut -d" " -f1); do
    ip netns exec ${NS} ip a | grep ${IP} && echo ${NS}
done

Bonding

ip link add bond0 type bond mode 802.3ad
ip link set eth0 master bond0
ip link set eth1 master bond0
ifdown eth0 && ifdown eth1 && ifup bond0
cat /proc/net/bonding/bond0
 
# Get error / dropped packet statistics
sudo netstat -i
 
ifenslave - Attach and detach slave network devices to a bonding device.

ARP

ip neighbor
 
# remove arp entry
ip neigh del 192.168.1.5 dev eth1
ip -s neigh f 192.168.1.5
arp -d 10.0.0.1
 
# remove all ARP entries
ip -s neigh flush all
 
# create ARP entry
ip neigh add 10.33.11.222 lladdr 00:11:22:33:44:55 dev dev-mgmt

Ping test
https://www.uptrends.com/tools/ping-test

Validate IP with BASH

if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  echo "success"
else
  echo "fail"
fi

Get primary IP address

hostname -I | cut -d" " -f1

Links
https://ipinfo.io/
https://www.cyberciti.biz/faq/linux-ip-command-examples-usage-syntax/
https://wiki.archlinux.org/index.php/VLAN
https://www.cyberciti.biz/tips/configuring-static-routes-in-debian-or-red-hat-linux-systems.html
https://www.cyberciti.biz/faq/howto-linux-configuring-default-route-with-ipcommand/
http://www.tecmint.com/ip-command-examples/
https://tty1.net/blog/2010/ifconfig-ip-comparison_en.html