April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Iptables rewirte for 8080 and 8443

Another way of achieving the same thing is to add an iptable redirection rule.

We have done it this way, because we didn’t want to add the xinit package to our standard configuration.

These instructions were created on a Debian Lenny system.

Create a new “if-up” script:
sudo vim /etc/network/if-up.d/jira-redirect

Make this its content:

#!/bin/bash
for i in $(sudo ifconfig  | grep ‘inet addr:’| grep -v ‘127.0.0.1’ | cut -d: -f2 | awk ‘{ print $1}’); do
        sudo iptables -t nat -I PREROUTING 1 -d $i -p tcp –dport 80 -j DNAT –to $i:8080
        sudo iptables -t nat -I PREROUTING 1 -d $i -p tcp –dport 443 -j DNAT –to $i:8443
done

This script will take all the IPs the server is using as shown by ifconfig, and will add the redirect rules for them.

Make the script executable:
sudo chmod +x /etc/network/if-up.d/jira-redirect

Create a new “if-down” script:
sudo vim /etc/network/if-down.d/jira-redirect-clearer

Make this its content:

#!/bin/bash
sudo iptables -F -t nat

This script will clear all the NAT rules by using the flush (-F) directive, when the networking is restarted.

Adding this “if-down” script better handles cases where you changed a networking setting and the old ones are still there until a reboot. however as this does clear ALL of the NAT settings, make sure this doesn’t affect other things on your setup.

Make the script executable:
sudo chmod +x /etc/network/if-down.d/jira-redirect-clearer

Restart the networking service for the changes to take affect:
sudo /etc/init.d/networking restart

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>