How to check default gateway and assigned IP address in Linux?
There are quite a few ways to do this in a Linux system.
However, in systemd or newer version of Linux systems which support the ip route command all the information is there already.
The output of the ip route command shows the default gateway and the assigned or primary IP address of the VM or server.
Here's an example to show the default gateway of a Linux system.
The IP Address after the word "default via" is the default gateway of the system.
Command is: ip r | grep default
To show only the default gateway IP Address, we need to use RegEx and match the IPV4 address only.
Here's the command: ip r | grep default | grep -Eoh '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
Sample output image:
To show the assigned primary IP address on the VM or server, type the command below.
Here's the command: ip r | grep -oP 'src \K\d+\.\d+\.\d+\.\d+'
Sample output image:
To show the whole output of ip route or ip r, don't include any parameters.
Sample image output of ip route or ip r command.
Explore the command line, it will make life easier.
Sirach 17:26 Return to the Almighty, turn aside from wrongdoing and totally detest evil.
Comments
Post a Comment