Problem with netstat?
Hi,
if I execute: Code:
[root@chips /root]# netstat -rn Kernel IP routing table 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, .*,," Code:
[root@chips /root]# netstat -rn Kernel IP routing table Thanks for your help, - Nick |
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. |
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 |
All times are GMT -5. The time now is 09:46 AM. |