Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When using the Shoutcast2 yellowpages there is a really annoying issue that it always uses the default IP the system uses for an outgoing conection to register itself even if the server is configured to listen on a different ip - I guess I don't need to mention that this makes no sense and the YP system unusable. Marking all other IPs of the systems as deprecated is not an option; I don't want the stream IP to be the default IP for other outgoing connections.

So what I'm looking for is a way to make those connections (always to yp.shoutcast.com:80) use a certain source IP address. An existing tool would be perfect but a solution that requires not-too-much coding would be fine, too. I also have root access on the machine so iptables-based solutions would be even better.

share|improve this question
up vote 3 down vote accepted

iptables can do this easily with the SNAT target:

iptables -t nat -A POSTROUTING -j SNAT \
    -o eth0 -p tcp --dport 80 --destination yp.shoutcast.com \
    --to-source $STREAM_IP
share|improve this answer
On a side-note: If anyone plans to use this for the same reason I do: Don't match by --destination, use the owner/uid match instead. The YP host is round-robin-ish and thus you'd need to create rule for all those ips. – ThiefMaster Oct 2 '12 at 11:40
Using the name will match all IPs returned by DNS. And usually something binding to "the wrong IP" because the routing table is improperly configured. If I could see it I could probably tell you what's wrong. – bahamat Oct 2 '12 at 16:37
The DNS returns only one ip; they round-robined the NS records. – ThiefMaster Oct 2 '12 at 16:58
ip route add dev eth0 src $SRC_ADDR
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.