Server Fault is a question and answer site for system and network administrators. 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

I am using Amazon Linux AMI in EC2.

Previously they allow me to enter different external port from internal port in the AWS web console (in the security groups). Now they only allow the same port for both internal and external port.

I need to have the same daemon to be visible from both port 80 and 8000. The daemon is now running on port 80.

How do I "port-forward" port 8000 to 80 in the same instance?

I am using the free usage tier (micro instance with Amazon Linux AMI)

share|improve this question
iptables -t nat -A PREROUTING -p tcp --dport 8000 -j REDIRECT --to-port 80

Something like this. :)

share|improve this answer
iptables v1.4.7: unknown option --dport' Try iptables -h' or 'iptables --help' for more information. – Afriza N Arief Mar 25 '11 at 14:37
@afriza I updated the answer. You need to specify protocol using -p option – Andrey Kuznetsov Jul 2 '14 at 10:53

sudo iptables -t nat -I PREROUTING -p tcp -i eth0 --dport 8000 -j DNAT --to-destination

the above command succeeds but both /proc/sys/net/ipv4/conf/eth0/forwarding and /proc/sys/net/ipv4/ip_forward contains 0 and are not writable even after using sudo.

share|improve this answer
check /etc/sysctl.conf. There you should add something like this net.ipv4.ip_forward = 1 for ../net/ipv4/ip_forward this should help – MealstroM Mar 28 '11 at 7:44

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.