Skip to Content

3 useful commands to Check Gateway in Linux

In Linux, your gateway is the device that handles network traffic between your computer and the rest of the world. It’s important to check your gateway periodically to make sure everything is running smoothly. In this blog post, we will discuss three different ways to check your gateway in Linux. We will also provide instructions on how to perform each method. Let’s get started!

Understanding gateway in Linux

A network gateway is a device that connects two networks together. In Linux, a gateway is usually a router. A gateway allows you to connect to different networks and access the resources on those networks. For example, you can use a gateway to connect to the Internet or to another network in your office.

Check gateway info with ip route command in Linux

To get the network gateway info, simply type “ip route” into the terminal. This will display the gateway info about your network interface. The gateway is typically listed under the “default” section.

$ ip route
default via 172.31.32.1 dev eth0 proto dhcp metric 100
172.31.32.0/20 dev eth0 proto kernel scope link src 172.31.37.167 metric 100

The ip command is a great way to view all of the information about your network interfaces. If you want to view more information about your network interfaces, you can use the “ip addr” command. This command displays all of the information about your network interfaces, including the IP address, netmask.

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 655
36 qdisc noqueue state UNKNOWN group default

The “ip link show” command is great way to view MAC address information about your network interfaces. To view the MAC address info, type “ip link show <interface>” into the terminal.

$ ip link show
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 0a:4f:94:5e:11:02 brd ff:ff:ff:ff:ff:ff

Find gateway info with route command in Linux

The route command is another way to view and modify the routing table on your system. To get the gateway, simply type “route -n” into the terminal. This will display all of the routes that are currently configured on your system. U means the route is ‘up’ and the G indicates that it is gateway.

$ route -n
Kernel IP routing table
Destination   Gateway     Genmask     Flags Metric Ref  Use Iface
0.0.0.0     172.31.32.1   0.0.0.0     UG  100  0    0 eth0
172.31.32.0   0.0.0.0     255.255.240.0  U   100  0    0 eth0

If you want to add a new route, you can use the “-add” option. For example, if you wanted to add a route for the 192.168.0.0/24 network, you would type “route add -net 192.168.0.0/24” into the terminal.

Check network interface gateway info with netstat command in Linux

The netstat command is an another way to view all of the active network connections on your system. To get the network gateway, simply type “netstat -rn” into the terminal.

$ netstat -rn
Kernel IP routing table
Destination   Gateway     Genmask     Flags  MSS Window irtt Iface
0.0.0.0     172.31.32.1   0.0.0.0     UG    0 0     0 eth0
172.31.32.0   0.0.0.0     255.255.240.0  U     0 0     0 eth0

Netstat will display all of the active network connections and their status. If you want to see more information about a specific connection, you can use the “-a” option. For example, if you wanted to see more information about the connection to 192.168.0.0/24, you would type “netstat -a | grep 192.168.0.0/24” into the terminal.

Hopefully, this blog post has helped you learn a few different ways to check your gateway in Linux. If you have any questions or comments, feel free to leave them below! Thanks for reading!