dslreports logo
 
    All Forums Hot Topics Gallery
spc
Search similar:


uniqs
201877

ipconfig
@verizon.net

ipconfig

Anon

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-

parkut
Crunch Addict
MVM
join:2001-12-15
Clinton Township, MI

parkut

MVM

assuming eth0 is your active interface

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

will reveal your gateway on redhat systems

firephoto
Truth and reality matters
Premium Member
join:2003-03-18
Brewster, WA

firephoto to ipconfig

Premium Member

to ipconfig
'route -n' on linux.

nwrickert
Mod
join:2004-09-04
Geneva, IL

1 recommendation

nwrickert to ipconfig

Mod

to ipconfig
I normally use

netstat -rn

Zaber
When all are gone, there shall be none
join:2000-06-08
Cleveland, OH

Zaber to ipconfig

Member

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

Joe Blow
@cableone.net

Joe Blow to ipconfig

Anon

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

Black Box to firephoto

Member

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.

pflog
Bueller? Bueller?
MVM
join:2001-09-01
El Dorado Hills, CA

pflog to nwrickert

MVM

to nwrickert
said by nwrickert:

I normally use

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

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

raw to Black Box

Premium Member

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
Mod
join:2004-09-04
Geneva, IL

nwrickert

Mod

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 Member
join:2001-01-17
Madison, AL

raw

Premium Member

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

nwrickert
Mod
join:2004-09-04
Geneva, IL

nwrickert

Mod

Okay, thank for clarifying.

IMO, "netstat -rn" is robust enough. It even works on Windows.
e9th
join:2003-07-12
Miami, FL

e9th to Black Box

Member

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

join:2001-03-10
Tustin, CA

Steve to pflog

to pflog
said by pflog:

Ditto, since it's portable (works on FreeBSD, Linux, SunOS, HUP-UX, etc)
And Windows

Black Box
join:2002-12-21

2 edits

Black Box to raw

Member

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

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

join:2001-03-10
Tustin, CA

Steve

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 Member
join:2006-06-06
Union, SC

1 edit

beldin to nwrickert

Premium Member

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!