2009/8/12 Florin Andrei <flo...@andrei.myip.org>: >>>> Is there a way to bind the listener to an interface using the interface >>>> name (eth5:smtp) instead of the IP (1.2.3.4:smtp)? >> >> No. The bind(2) system call specifies an address. Not an interface, >> and not the route. Connections with source address of X are not >> necessarily sent out via interface X. The interface is chosen >> depending on the destination of the connection. > > I understand. It makes perfect sense from the perspective of the programmer. > > But switch the perspective and look at it from the p.o.v. of the sysadmin. > In that case, it would be so nice to say "hey, bind to interface ethX and > stay there". > > It's not unheard of either. Right now, on my home server, I've at least > three services running that are configured like that: samba, dhcpd and > mediatomb (a UPnP multimedia server). So it's not just doable, but quite a > widespread practice among open source projects.
Right, but it'd introduce unnecessary complexity and possible unexpected behaviour, something strongly frowned upon. As you mention, there is software that can do this (the fact that it's open-source isn't really relevant though), but I'd argue it's just something postfix doesn't need. "It's not that kind of service", or something. There's also the matter of having multiple IP addresses on an interface. My own experience is limited, I can't remember if you can add another address to an interface without using aliases. My experience is linux-only, I use colons in the aliased interface names, that'd cause problems with IPv6. If I use a tagged VLANs (802.1q) then I'll have dots in the name, that might look like an IPv4 address. *BSD might do things differently again, it could be very messy. But if you insist, you could script this behaviour yourself. Maybe there's a sane way to get this out of the kernel, this is just the quickest thing I could come up with in my sleep-deprived state. grep out the lines you want, cut it up to grab the addresses, and feed it to postconf -e, whatever makes you happy. This is strictly a "works for me" example. #!/bin/sh # this is crap, won't handle ipv6, isn't tested, no error-checking, etc... ip addr | while read LINE do case $LINE in [0-9]:*) # Start processing an interface IFNAME=`echo $LINE | cut -d':' -f2 | awk '{ print $1 }'` echo -n "$IFNAME: " IP='' while read IFLINE do # Build the list of addresses case $IFLINE in inet6*) break ;; inet*) IP="$IP`echo -n $IFLINE | awk '{ print $2 }' | cut -d'/' -f1`, " ;; esac done echo "$IP" | sed 's/, $//' ;; esac done postconf -e inet_interfaces="`./addr.sh | grep eth0 | cut -d' ' -f2-`" ; postfix reload