Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I need to create a route in iptables which allows to use my second IP address as source(not default one) when i connect to an external FTP server. How do i create that route for iptables? i am not very familiar with Linux/Redhat any help on the commands would be highly appreciated.

Thanks for any direction!

share|improve this question
up vote 2 down vote accepted

You need to use a source NATing rule like:

$ sudo iptables -t nat -A POSTROUTING -s your_private_ip -d FTP_server_ip -j SNAT --to-source your_public_ip

You can also specify the interface using -i eth0.

share|improve this answer
Thanks aflot for the tips. May i know, -i eth0 is another way to do it ?. By the way, how can i bind the secondary IP address to the server ? i have 5 available IP addresses in the rance, how can i bind one to the server as secondary IP to use it in the route ? – taras Dec 13 '10 at 15:02
@taras: I mean you can restrict the rule to be applied on specific interface only if required. You can bind another IP using the command: ifconfig eth0:0 your_ip netmask your_mask. – Khaled Dec 13 '10 at 15:12
just wanted to check, in your code: -s your_private_ip is it default public IP or default local IP ? thanks for comments, i really appreciate your help! – taras Dec 13 '10 at 16:34
@taras: You can specify the matched source IP address using -s your_private_ip. So, this will match the traffic sent from this IP. Similarly, using -d FTP_server_ip will restrict the match further to the packets destined to the FTP server. – Khaled Dec 13 '10 at 16:45
i got this error: No chain/target/match by that name. – taras Dec 13 '10 at 17:04

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.