dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
121446
share rss forum feed


ipconfig

@verizon.net

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/networking/staticip.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-


parkut
Crunch Addict
Premium,MVM
join:2001-12-15
Harrison Township, MI
kudos:7

assuming eth0 is your active interface

cat /etc/sysconfig/network-scripts/ifcfg-eth0

will reveal your gateway on redhat systems



firephoto
We the people
Premium
join:2003-03-18
Brewster, WA
reply to ipconfig

'route -n' on linux.



nwrickert
sand groper
Premium,MVM
join:2004-09-04
Geneva, IL
kudos:7

1 recommendation

reply to ipconfig

I normally use

netstat -rn



Zaber
When all are gone, there shall be none

join:2000-06-08
Cleveland, OH
reply to ipconfig

From a terminal you can use either 'route -n' or 'ip route show'



Joe Blow

@cableone.net
reply 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.



Black Box

join:2002-12-21
reply 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.

--
Keep It Safe, Stupid!
Yes, I CanChat. Can You?


pflog
Bueller? Bueller?
Premium,MVM
join:2001-09-01
El Dorado Hills, CA
kudos:3
reply to nwrickert

said by nwrickert:

I normally use

netstat -rn
Ditto, since it's portable (works on FreeBSD, Linux, SunOS, HUP-UX, etc)
--
"The Dude abides."


raw
War Eagle
Premium
join:2001-01-17
Madison, AL
reply 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
 


nwrickert
sand groper
Premium,MVM
join:2004-09-04
Geneva, IL
kudos:7

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.



raw
War Eagle
Premium
join:2001-01-17
Madison, AL

No, I'm saying that Black Box See Profile's 'more robust' method (see the second command) failed.



nwrickert
sand groper
Premium,MVM
join:2004-09-04
Geneva, IL
kudos:7

Okay, thank for clarifying.

IMO, "netstat -rn" is robust enough. It even works on Windows.


e9th

join:2003-07-12
Miami, FL
reply 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 '*'.



Steve
I know your IP address
Consultant
join:2001-03-10
Foothill Ranch, CA
kudos:5
reply to pflog

said by pflog:

Ditto, since it's portable (works on FreeBSD, Linux, SunOS, HUP-UX, etc)
And Windows
--
Stephen J. Friedl | Unix Wizard | Microsoft Security MVP | Tustin, California USA | my web site


Black Box

join:2002-12-21

2 edits
reply 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}'

--
Keep It Safe, Stupid!

Yes, I CanChat. Can You?


beerbum
Premium
join:2000-05-06
Reading, PA
kudos:1
Reviews:
·Comcast

1 edit

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


Steve
I know your IP address
Consultant
join:2001-03-10
Foothill Ranch, CA
kudos:5

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...


beldin
Script Monkey number 50
Premium
join:2006-06-06
Union, SC
Reviews:
·Charter

1 edit
reply 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!
--
DSL Extreme 6.0