LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2002, 05:25 PM   #1
NiM
Member
 
Registered: Aug 2001
Location: UK
Distribution: Mandrake 8.0
Posts: 33

Rep: Reputation: 15
Problem with netstat?


Hi,

if I execute:

Code:
[root@chips /root]# netstat -rn                                                 Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.0.0     0.0.0.0         255.255.255.0   U        40 0          0 eth0
80.195.244.0    0.0.0.0         255.255.255.0   U        40 0          0 eth1
127.0.0.0       0.0.0.0         255.0.0.0       U        40 0          0 lo
0.0.0.0         80.195.244.1    0.0.0.0         UG       40 0          0 eth1
0.0.0.0         192.168.0.1     0.0.0.0         UG       40 0          0 eth0
That's all correct, my cable internet is on eth1, and linux routes all internet traffic to it fine.

Than, I execute a command that should find my internet IP, which changes dynamicly and is assingned via DHCP. The correct IP is however shown in ifconfig eth1...

Code:
[root@chips /root]# netstat -rn | egrep ^0.0.0.0 | sed -e "s,.* ,,g" | xargs /sbin/ifconfig | grep "inet.addr" | sed -e "s,.*addr:,," -e "s, .*,,"
It returns nothing, and strangely, my internet stops working, so I check out the routing tables again...

Code:
[root@chips /root]# netstat -rn                                                 Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.0.0     0.0.0.0         255.255.255.0   U        40 0          0 eth0
127.0.0.0       0.0.0.0         255.0.0.0       U        40 0          0 lo
62.0.0.0        0.0.0.0         255.0.0.0       U        40 0          0 eth1
0.0.0.0         192.168.0.1     0.0.0.0         UG       40 0          0 eth0
Huh? what happned there? The IP finding code I used used to work, however, my eth1 recently changed IRQs and I had to set it up again, is there something I've forgotten to do when setting it up again, oris there an error in the IP finding code?

Thanks for your help,
- Nick

Last edited by NiM; 07-01-2002 at 05:36 PM.
 
Old 07-02-2002, 03:00 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
I don't know why your routing table gets screwed up, but as far as I can see the code you are using to get your ip address won't work. Here is why:

First you run 'netstat -rn | egrep ^0.0.0.0'. This will give you every line starting with 0.0.0.0 which will be:

0.0.0.0 80.195.244.1 0.0.0.0 UG 40 0 0 eth1
0.0.0.0 192.168.0.1 0.0.0.0 UG 40 0 0 eth0

Then you pipe it through 'sed -e "s,.* ,,g"'. This will replace any set of characters that is followed by a space with nothing. So what you will have left is:

eth1
eth0

Next you pass it to /sbin/ifconfig using the xargs command. Now since you got two lines back instead of just one. The command that will be run will be:

/sbin/ifconfig eth1 eth0

If you try running that command you should get an error. So it wouldn't matter how you parse the rest of the information from it. I assume where the code used to work you would had only one interface.

But you said you get the ip through dhcp. I use dhcpcd and this is how I get the ip address that was retrieved.

export `grep IPADDR /etc/dhcpc/dhcpcd-eth?.info`
This ofcourse assumes there is only one interface which retrieves it's ip through dhcp. You can replace the ? with the right number if you want it to get a specific one. That command sets the variable IPADDR so you can then just use $IPADDR for whatever you wanted to do with it.
 
Old 07-02-2002, 05:50 AM   #3
NiM
Member
 
Registered: Aug 2001
Location: UK
Distribution: Mandrake 8.0
Posts: 33

Original Poster
Rep: Reputation: 15
Smile Thanks!

Hi,

Hmm, maybe before, I only had 1 line beginning with 0.0.0.0, it's supposed to find the internet NIC and grab the IP from it...

Still, your code's much easier And now at least I can echo it when I need it!

Cheers & Thanks for your help!

- Nick
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
possible intrusion? netstat branden_burger Linux - Security 3 03-03-2005 09:54 AM
netstat -s r_213 Linux - Networking 2 01-27-2005 06:45 AM
netstat -i r_213 Linux - Networking 4 09-09-2004 06:10 AM
netstat sopiaz57 Linux - Networking 1 10-14-2003 03:39 PM
netstat -l output help dai Linux - Security 2 07-02-2003 03:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration