|
ipconfig
Anon
2007-Oct-19 1:35 pm
How do I check the default gateway on an unix/linux machine? I was told to quote: Please go through these series of checks, before posting.
Let's start at check one.
Check #1: Are you sure you are behind a NAT device in NAT mode?
Go to »www.portforward.com/netw ··· icip.htm
Select your OS.
Follow the steps to locate your IP address and the default gateway.
Check your IP:
a) 10.0.*.* to 10.255.*.*
b) 172.16.*.* to 172.31.*.*
c) 192.168.*.*
So how do I do that on unix/linux machines(s)? -Thanks- |
|
parkutCrunch Addict MVM join:2001-12-15 Clinton Township, MI |
parkut
MVM
2007-Oct-19 1:46 pm
assuming eth0 is your active interface
cat /etc/sysconfig/network-scripts/ifcfg-eth0
will reveal your gateway on redhat systems |
|
firephotoTruth and reality matters Premium Member join:2003-03-18 Brewster, WA |
to ipconfig
'route -n' on linux. |
|
1 recommendation |
to ipconfig
I normally use
netstat -rn |
|
ZaberWhen all are gone, there shall be none join:2000-06-08 Cleveland, OH |
to ipconfig
From a terminal you can use either 'route -n' or 'ip route show' |
|
|
Joe Blow to ipconfig
Anon
2007-Oct-19 10:48 pm
to ipconfig
In Debian and related distributions running the Gnome GUI you can just open the Gnome Network tool, click on the netstat tab, choose Routing Table Information, and then click on the Netstat button. Your information will then be displayed for you.
It's basically the same data displayed as when you run netstat -r from a bash prompt. |
|
|
to firephoto
To print only the default gateway you can use: bash code: route -n | grep 'UG[ \t]' | awk '{print $2}'
Please note the space before \t. A more robust version that actually parses the line and does not depend on the gateway being up and the interface name not containing the sequence UG would be: bash code: route -n | grep '^0\.0\.\0\.0[ \t]\+[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]\+[ \t]\+0\.0\.0\.0[ \t]\+[^ \t]*G[^ \t]*[ \t]' | awk '{print $2}'
This version is better for including in a script that may run unattended. |
|
pflogBueller? Bueller? MVM join:2001-09-01 El Dorado Hills, CA |
to nwrickert
Ditto, since it's portable (works on FreeBSD, Linux, SunOS, HUP-UX, etc) |
|
rawWar Eagle Premium Member join:2001-01-17 Madison, AL |
to Black Box
Hmm... something seems to be amiss. scalawag kismet # netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 ra0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 ra0
scalawag kismet # route -n | grep '^0\.0\.\0\.0[ \t]\+[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]\+[ \t]\+0\.0\.0\.0[ \t]\+[^ \t]*G[^ \t]*[ \t]' | awk '{print $2}'
scalawag kismet # route -n | grep 'UG[ \t]' | awk '{print $2}'
192.168.1.1
|
|
|
I'm not seeing any obvious problem.
It is showing your gateway as 192.168.1.1, and that is most likely a home router. To find the external router, you would need to browse to your router page and pick up the WAN information there. |
|
|
rawWar Eagle Premium Member join:2001-01-17 Madison, AL |
raw
Premium Member
2007-Oct-20 1:03 pm
No, I'm saying that Black Box 's 'more robust' method (see the second command) failed. |
|
|
Okay, thank for clarifying.
IMO, "netstat -rn" is robust enough. It even works on Windows. |
|
e9th join:2003-07-12 Miami, FL |
to Black Box
The second example fails when the gateway's address ends in a single digit. E.g., 192.168.1.10 will be found, 192.168.1.1 will not.
Try replacing the 2nd occurrence of '\+' with an unescaped '*'. |
|
SteveI know your IP address
join:2001-03-10 Tustin, CA |
to pflog
said by pflog:Ditto, since it's portable (works on FreeBSD, Linux, SunOS, HUP-UX, etc) And Windows |
|
2 edits |
to raw
Sorry, I've missed a "*". Now it should work on any machine, not only mine. bash code: route -n | grep '^0\.0\.\0\.0[ \t]\+[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*[ \t]\+0\.0\.0\.0[ \t]\+[^ \t]*G[^ \t]*[ \t]' | awk '{print $2}'
|
|
beerbum Premium Member join:2000-05-06 behind you.. Motorola MB8600 ARRIS TG862 Asus RT-AC5300
1 edit |
beerbum
Premium Member
2007-Oct-26 1:43 am
said by Black Box:Sorry, I've missed a "*". Now it should work on any machine, not only mine. why complicate things.. use ifconfig -a this will show the current config/status of all your net devices.. like this [me@banana]$$ ifconfig -a lo0: flags=2001000849 mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 elxl0: flags=1000843 mtu 1500 index 2 inet 192.168.1.5 netmask ffffff00 broadcast 192.168.1.255 ether 0:10:5a:5f:e5:22 |
|
SteveI know your IP address
join:2001-03-10 Tustin, CA |
Steve
2007-Oct-26 11:13 am
said by beerbum:this will show the current config/status of all your net devices.. like this [me@banana]$$ ifconfig -a lo0: flags=2001000849 mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 elxl0: flags=1000843 mtu 1500 index 2 inet 192.168.1.5 netmask ffffff00 broadcast 192.168.1.255 ether 0:10:5a:5f:e5:22 I don't see a default gateway in there... |
|
beldinScript Monkey number 50 Premium Member join:2006-06-06 Union, SC 1 edit |
to nwrickert
said by nwrickert:IMO, "netstat -rn" is robust enough. It even works on Windows. And that will be a first! Something that actually works in Windows! |
|