[Gllug] re: listening on more than 1 IP address

Simon A. Boggis simon at dcs.qmul.ac.uk
Fri Sep 26 23:58:02 UTC 2003


On Fri, 2003-09-26 at 10:55, t.clarke wrote:
> Thanks guys for the various replies and example code
> 
> I was rather hoping that there would be a way of avoiding binding to two
> sockets and using select/poll to pick the one to read from !
> I have done this before in some other program and it works, so I guess I
> could re-use the code - I was just wondering if there was an easier way I
> was somehow missing.

I don't think there is, unless you do packet mangling using IP tables or
IP chains to achieve a similar effect; but that requires that the
packets actually come to you in the first place, which means that you
need to be the default router, or get it to do it for you.

> Upon reflection it occurs to me that in the particular situation I am
> currently listening on 127.0.0.1 only, but I need also to listen to a
> 192.168.123.001 address (being the internal LAN ethernet card).  So I guess if
> the application that currently connects to 'localhost' (which maps to
> 127.0.0.1) connects to 'machine-name' (which maps to 192.168.123.001) I should
> then be able to talk to the server from both within its own host machine and
> from others machines on the internal LAN.  THis might seem to be a bit of a
> bodge, but it should work  - since I can telnet to 192.168.123.001 on the
> same machine.
> 
> Any problems with this approach ?

Not so far as I can see - it'd work fine, provided (as you say) you
remember to connect to 192.168.123.1 from local processes too.

A sort-of-only-semi-related-to-this-topic, but useful (IMHO so I'm going
to witter on anyway) trick is to add an extra address (from a subnet
which you don't use for something else!) to your loopback interface:

# ip addr ls dev lo 
1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet AAA.BBB.CCC.DDD/32 scope global lo:0
    inet6 ::1/128 scope host

This gives you rather natty behaviour in that for a multi homed machine
you now have a single address to connect to, which is completely
independent of interface. Even better, if I bind my services to this
address, and want to move it I can do so very quickly and transparently
since the address is not associated with the physical machine in
question.

I this on my linux-based router/firewalls for running DNS caches and
other "network services". The machines in question have 10 interfaces,
and at least 10 addresses bound to these, but each also gets a
device-independent address (on another subnet reserved for issuing such
addresses). Machines which aren't routers given such addresses need to
have static routes to their address configured on the routers.

Have a good weekend all,

Simon

-- 
----------------------------------------------------------------------
Dr Simon A. Boggis                                  Systems Programmer
Department of Computer Science,                     Tel. 020 7882 7522
Queen Mary, University of London, London E1 4NS UK. 
---- GPG public key <http://www.dcs.qmul.ac.uk/~simon/#publickey> ----


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list