Linux: Default Gateway

Note

The net-tools linux package is an old one, and provides a large number of standard commands:

  • arp
  • ifconfig
  • iptunnel
  • iwconfig
  • nameif
  • netstat

net-tools was deprecated in 2011. While is it still available it is advisable to move on to more modern commands.

The standard command for showing IP address in Linux is ip a. ip also provides an option to view configured gateways:

ip r
ip r
ip r
ip r

Here is an example of adding a default gateway:

ip route add default via 192.168.1.1

If your distribution or container is missing this command you can add it with:

dnf -y install iproute2
apt -y install iproute2
apk add iproute2
pacman -Syu iproute2