Can an network interface have no pre-defined IP source address?

Can an network interface have no pre-defined IP source address?

Post by Andrew S. Haydo » Sat, 17 May 2003 10:45:09



Hi, Gurus,

Is it possible for a network interface which source IP address is
determined by the destination IP address? Or the source IP address is
dynamic?
How the kernel recognize an IP address is the local host?

Thanks,

Andrew

 
 
 

Can an network interface have no pre-defined IP source address?

Post by Grant Taylo » Sat, 17 May 2003 12:27:35



Quote:> Is it possible for a network interface which source IP address is
> determined by the destination IP address? Or the source IP address
> is dynamic?

An IP interface has one IP address, pretty much by definition.
Optionally it may have some aliases; Linux reports these as additional
interfaces of the form "foo0:1".

A locally gnerated packet has, in general, a source *socket*.  The
protocols associated with this socket (the domain and type specified
in the socket(2) call) and the way it was bound by the application
will define what the source address is.

Typically the source address may be any loopback address (127.0.0.0/8)
or the address of any local interface.  One may add either interface
aliases or dummy interfaces (depending on where routing requires the
address to live) to provide additional local IP addresses.

Applications have rather less control over how packets will leave the
box.  Typically packets are routed out an interface according to the
routing table, generally this is exactly what you want.

Quote:> How the kernel recognize an IP address is the local host?

Generally the local addresses are configured at boot time via static
information or dhcp, bootp, ip= kernel arguments, etc.

So the kernel "just knows".  Otherwise it wouldn't be much use ;)

--
Grant Taylor - gtaylor<at>picante.com - http://www.picante.com/~gtaylor/
 Linux Printing Website and HOWTO:  http://www.linuxprinting.org/

 
 
 

1. Host primary interface address as source address in IP header

I'm running kernel 2.0.32 from Redhat 5.0. I have my Linux box with both
a serial port out to a permanent modem link and an ethernet to my
internal LAN.

The ppp is configured with the IP address allocated by the ISP
(139.x.y.z), and I've configured the ethernet with an IP address from my
allocated class C subnet. All is happy, my LAN can gateway through to the
'net, everybody out on the net can get back (yes, I know, the firewall
happens next week :-)).

Anyway, the problem is when I telnet/ftp/other from the Linux box
*itself* to the net. The source address in the IP packets has the address
of the ppp port, not the address reported by gethostbyname. This makes it
difficult for our office (for example) to allow me in by IP address,
because the IP address is something that the DNS refers back to my ISP,
rather than my allocated address.

Anyway, long and involved story, but it caused me to start grovelling
around in the networking source (it was also an excuse to start hacking
Linux). I worked my way through connect() and found ip_my_addr() in
net/ipv4/devinet.c. This allocated the loopback address (127.0.0.1) to
the source address of an outgoing IP packet. Later, ip_build_header in
net/ipv4/ip_output.c replaces the loopback address with either the source
address of the route or the interface address of the outgoing port.

I hesitate greatly before saying that this is wrong, but I would have
thought that the first address returned from gethostbyname(hostname()) is
what should be in the source IP address of the packet.

Am I off the beaten track, totally confused, got it all wrong, or <gasp>
found a bug?

Ron

2. uname reports 'unknown'

3. EIDE problems...

4. One Process on the machine having two IP address and two ethernet interface.

5. pine & windows-1251

6. problem in pinging...: linux having two interfaces and on the same subnet ip addresses.

7. Where to put who may log in via FTP

8. discovering the ip address of an interface without knowing any network info (like network, subnet, etc)

9. Setting default source IP address with multiple interface machine?

10. Open N4x from command line with pre-defined URL

11. Pre-defined installation

12. How to start a daemon on a pre-defined tty!