====== Default Gateway ====== ===== Find current setting ===== ==== IPv4 ==== Find Default Gateway in Linux using following options: $ ip route show --------------- default via 192.168.1.1 dev eth1 proto static 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.100 metric 1 Alternative option using route: $ route -n ---------- Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth1 192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 The above output shows my default gateway is 192.168.1.1. UG stands for the network link is Up and G stands for Gateway. ==== IPv6 ==== Find Default Gateway in Linux using following options: $ ip -6 route show 2001:1c00:2e16:720a::806 dev enp1s0 proto kernel metric 100 pref medium 2001:1c00:2e16:720a::/64 dev enp1s0 proto ra metric 100 pref medium fdaa:66:67:a::806 dev enp1s0 proto kernel metric 100 pref medium fdaa:66:67:a::/64 dev enp1s0 proto ra metric 100 pref medium fe80::/64 dev enp1s0 proto kernel metric 1024 pref medium default via fe80::ee08:6bff:fe84:2043 dev enp1s0 proto ra metric 100 pref medium ===== Setting Default Gateway ===== ===== IPv4 ===== In case of DHCP the gateway is communicated via the DHCP options. Here is the list of the most common DHCP options exchanged with clients: * DHCP option 1: subnet mask to be applied on the interface asking for an IP address * DHCP option 3: default router or last resort gateway for this interface * DHCP option 6: which DNS (Domain Name Server) In case of manual configuration the gateway is specified in the /etc/network/interfaces file: cat /etc/network/interfaces --------------------------- auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 ===== IPv6 ===== IPv6 works very differently from IPv4 when it comes to gateways. With IPv4, you need to specify a gateway manually or via a DHCP option. With IPv6, the IP stack locates gateways automatically by using ICMP-v6 Neighbor Discovery packets. Specifically, a client will listen for Router Advertisements, which may be sent gratuitously by a router or as a response to a Router Solicitation package. In addition to that a default route can be set with: # ip -6 route add default via xx:xx:xx::xx dev eth0