Linux/ip
< Linux
Install ip tool
apt install iproute2
Add static IP
sudo ip addr add 192.168.1.2/24 dev eth0; sudo ip route add default via 192.168.1.1 dev eth0;
Remove static IP
sudo ip addr del 192.168.1.2/24 dev eth0;
Bring interface online
ip link set dev <interface> up ip link set dev <interface> down
Interface Alias
Change name: (change enp39s0 to eth0)
ip link set enp39s0 name eth0
Add Alias: (add eth0 to enp39s0)
ip link property add dev enp39s0 altname eth0 ip link property del dev enp39s0 altname eth0
Add Temporary IP to Interface
ip a add 192.168.178.2/24 dev eth0
Route
Print routes:
ip route
Add default route:
sudo ip route add default via 192.168.1.1 dev eth0;
Add route:
sudo ip route add 172.10.1.0/24 via 192.168.1.1 dev eth0;
Ways to get Private IP Address
ifconfig
ifconfig
ip addr
# will need to be parsed ip addr ip a ip addr show ip -br -c a
# parsed
ip route get 1 | awk '{print $(NF-2);exit}'
ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p'
ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p'
read -r _{,} gateway _ iface _ ip _ < <(ip r g 1.0.0.0) ; printf '%-12s %s\n' gateway $gateway iface $iface ip $ip # [1]
hostname
# will need to be parsed hostname -I
# parsed hostname -I | cut -d' ' -f1
Ways to Get IPv4 Public IP Address
curl
curl ip.ixota.com curl ifconfig.me curl api.ipify.org curl icanhazip.com
wget
wget -qO- ipecho.net/plain
dig
dig +short myip.opendns.com @resolver1.opendns.com
Ways to Get IPv6 Public IP Address
curl
curl https://i-p.show
curl https://ipv6.icanhazip.com curl http://ip6only.me/api/ # not as clean
curl -6 icanhazip.com curl -6 https://ifconfig.co curl -6 ip.sb curl -6 https://ipv6.icanhazip.com curl https://api64.ipify.org