Determining interface to access IP


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Determining interface to access IP
# 1  
Old 02-17-2010
Determining interface to access IP

Hello

I've got a server with multiple NICS. In a script I want to log the outbound interface. Is there an easy way I can do this so that the output looks something like this:

host(xxx.xxx.xxx.xxx): Opening connection to ...

Obviously, getting the host is simple with hostname. But how can I determine the interface. Some netstat invocation?

Last edited by brsett; 02-17-2010 at 04:26 PM..
# 2  
Old 02-17-2010
If this script is being called by the daemon or what have you, maybe the information is reported to the script in environment vars? Try 'set' for a list of them. Otherwise you have the problem of finding out which socket is your socket on top of everything else...
# 3  
Old 02-17-2010
I don't know why I need the socket, I just need the route. On modern Linux I can do the following as it turns out (just learned this):

/sbin/ip route get <remote_ip>

And it is in that output. But that is a little platform dependent. I was hoping there was a System V mostly-portable way to do this.

Last edited by brsett; 02-17-2010 at 04:26 PM..
# 4  
Old 02-18-2010
Quote:
Originally Posted by brsett
I don't know why I need the socket, I just need the route.
You failed to mention that you had the remote IP. My thoughts were along the lines of how in the heck do I get that without knowing anything about what program made what connection where?

Another complication is that there may be several valid routes, not just one.
# 5  
Old 02-18-2010
Quote:
Originally Posted by Corona688
You failed to mention that you had the remote IP. My thoughts were along the lines of how in the heck do I get that without knowing anything about what program made what connection where?

Another complication is that there may be several valid routes, not just one.
Yeah, there is no route without a destination endpoint.

I don't think multiple routes should matter, UNIX will use the first valid entry in the routing table. I want the interface used to get to that route.

I guess there isn't any clearly (or even mostly) portable way to do this from the shell. Darn.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Adding a network interface to a bonded interface

I have a RHEL 5 system with a bonded interface configure using only one network port (eth0). So I have config file for ifcfg-bond0 and ifcfg-eth. I'd like to configure eth5 to be the second SLAVE in the bond. My question is, after I modify ifcfg-eth5, can I add eth5 to the bond0 interface without... (1 Reply)
Discussion started by: westmoreland
1 Replies

2. UNIX and Linux Applications

Access to network interface (Mac-network)

Hi, I'm a italian student. For my thesis I develop a gateway with protocol 6lowpan. For that I must access to network interface to develope my personal stack based on standard 802.15.4. Can you help me? I need an explanation for that. (0 Replies)
Discussion started by: berny88
0 Replies

3. Shell Programming and Scripting

Determining whether given string is path or not

I have an issue while determing whether given string is unix path or not There is a text file which is normally a report in that at some place we have unix path as shown below /opt/smart/dev/eur/sources/sqr and not unix path as shown below Threshold Year/Month/Ref/ActLine/OUC Is there... (3 Replies)
Discussion started by: lalitpct
3 Replies

4. Programming

determining the IP of a function

Is there a way to determine the "Instruction Pointer" of a function in c++, and if so can someone tell me? (5 Replies)
Discussion started by: neur0n
5 Replies

5. Programming

Determining file access perms for current process

Stupid question, but is there an ANSI C stdlib function that will do this for me? I want to pass the function a path and determine if the current process can read/write/execute on the path. I suppose I can whip something up using fstat and then determining the current process's user/group IDs and... (6 Replies)
Discussion started by: DreamWarrior
6 Replies

6. IP Networking

Need a bridge from an ethernet interface to a serial interface

This is my situation DOS pc serial cable (sl0) Linux Pc eth1 192.168.0.10 <-------------------->192.168.0.2 <------------>192.168.0.1 (router) I connected the linux pc and the dos pc with a SLIP (serial line internet protocol), so they can communicate in the sl0 interface. ... (3 Replies)
Discussion started by: mghis
3 Replies

7. SCO

Change SCO - GUI or Desktop interface to DOS based interface

Hi all I have installed a demo version of SCO OpenServer 5.0.2, I finally found it is Desktop Interface, I would like to know how to change its interface to dos based interface? If you have any ideas, please tell me then. Thank you (2 Replies)
Discussion started by: TinhNhi
2 Replies

8. Solaris

Command line Interface or GUI Interface not shown on solaris

Dear all, I am a newbie in solaris and I need your advice. I have a Solaris version 5.9 installed on Sunfire V240. I am able to ssh the machine from putty remotely. My problem is that I cannot see the display from KVM switch I have connected to it. I need also to be able to see the GUI... (2 Replies)
Discussion started by: mbouster
2 Replies

9. IP Networking

Help determining what's blocking ports

I'm fairly new to networking and am trying to figure our network out, as I was recently assigned to be network administrator where I work. I was trying to get utorrent to work but am not having success in figuring out what's blocking my ports. As of now, I'm getting connected from a mikrotik... (11 Replies)
Discussion started by: brandonros
11 Replies
Login or Register to Ask a Question