Getting the gateway IP address of your machine is a very important trick sometimes. This is very easy on Linux.
Use the ip route
command on Linux to print information about the IP routing. This includes the gateway IP address.
┌──[jason@192.168.1.2]─[~/Videos] └──╼ ╼ $ ip route | grep default | awk '{print $3}' 192.168.1.1 |
This is very simple and works just fine.
This is how to use the ip route
command to print the IP address of your computer.
┌──[jason@192.168.1.2]─[~/Videos] └──╼ ╼ $ ip route | sed -n -e '3{p;q}' | awk '{print $9}' 192.168.1.2 |
This command will print only the 3rd line of output on STDOUT.
sed -n -e '3{p;q}' |
Then, use this command to only print the 9th column of output on that line.
awk '{print $9}' |
Use this command to get the external Internet-facing IP address that you currently are issued from your Internet Service Provider.
┌──(john㉿DESKTOP-PF01IEE)-[/mnt/c/Users/Intel i5] └─$ dig +short myip.opendns.com @resolver1.opendns.com 203.125.10.200 |
This is the proper way to accomplish this easily. There are many ways to get this kind of information. You may also use the IP(1) command to get routing information.
┌──(john㉿DESKTOP-PF01IEE)-[/mnt/c/Users/Intel i5] └─$ ip -h -4 route default via 172.26.32.1 dev eth0 172.26.32.0/20 dev eth0 proto kernel scope link src 172.26.43.110 |
This shows the network route I am currently using with Kali Linux.