Port Forwarding apache2 default port to 8080 using IP Tables
- Check apache2 default port
ubuntu@server1:~$ sudo vi /etc/apache2/ports.conf
Listen 80
Our default port for apache2 service is 80, now we test this by using the curl command
ubuntu@server1:~$ curl server1:80 => should output apache2 default html
ubuntu@server1:~$ curl server1:8080 => should output “curl: (7) Failed to connect to localhost port 8080: Connection refused”
- Forward the default port to 8080
We’re going to use ip tables and nat for the forwarding part, with that set type this below command:
ip tables -A PREROUTING -i <interface> -t nat -p tcp –dport 8080 -j REDIRECT –to-port 80
with that command we’ve successfully forward our apache2 default port (80) to port 8080, if we want to test this login to other server (ex: ubuntu@server2) and use the curl command
ubuntu@server1:~$ curl server1:8080 => should output “curl: (7) Failed to connect to student port 8080: Connection refused”
ubuntu@server2:~$ curl server1:8080 => should output the apache2 default html