codeaprendiz.github.io

DevOps Essentials

View on GitHub

ip

ip

NAME

ip - show / manipulate routing, devices, policy routing and tunnels

SYNOPSIS

ip [ OPTIONS ] OBJECT { COMMAND help }
OBJECT := { link addr addrlabel route rule neigh tunnel maddr mroute monitor }
OPTIONS := { -V[ersion] -s[tatistics] -r[esolve] -f[amily] { inet inet6 ipx dnet link } -o[neline] }

OBJECT

address or addr

protocol (IP or IPv6) address on a device.

protocol (IP or IPv6) address on a device.

address add

add new protocol address.

network device

netns

network namespace

route

Manipulate route entries in the kernel routing tables keep information about paths to other networked nodes.

EXAMPLES

$ ip route
default via 10.128.0.1 dev ens4 proto dhcp src 10.128.0.38 metric 100 
10.128.0.1 dev ens4 proto dhcp scope link src 10.128.0.38 metric 100 
$ ip netns add red

$ ip netns add blue
# ip netns
red
blue
$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 42:01:0a:80:00:26 brd ff:ff:ff:ff:ff:ff

OR

$ ip -n red link 1: lo: mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00


- Similarly you can run the arp command on the host and inside the network namespace


```bash
### On the host
$ arp
Address                  HWtype  HWaddress           Flags Mask            Iface
_gateway                 ether   42:01:0a:80:00:01   C                     ens4

## inside the namespace
$ ip netns exec red arp
$ ip link add veth-red type veth peer name veth-blue
$ ip link set veth-red netns red
$ ip link set veth-blue netns blue
$ ip -n red addr add 192.168.15.1 dev veth-red
$ ip -n blue addr add 192.168.15.2 dev veth-blue
$ ip -n red link set veth-red up
$ ip -n blue link set veth-blue up
$ ip netns exec red ping 192.168.15.2
$ ip netns exec red arp