I'm trying to redirect all HTTP/HTTPS trafic from one server to another (via IP).
I do use the ufw
firewall. How can I configure it do to so?
I'm trying to redirect all HTTP/HTTPS trafic from one server to another (via IP).
I do use the ufw
firewall. How can I configure it do to so?
(You will need admin privileges for this, so login as root or use sudo accordingly)
One easy solution is to use
iptables
for that:will redirect all traffic in the interface
eth0
(option: -i) received on port 80 and 443 (option: --dport 80, 443) to afoo_serverip
IP address on port 80 or 443.After tested you can just save your current iptables rules with
and restore them with
Knowing this, the options to restore the rules at boot time are multiple. The most simple one I can think of is to edit your
/etc/rc.local
and append the line/sbin/iptables-restore < /etc/iptables.rules
to it.I do not think
ufw
can do any of this just by itself.It's possible to configure ufw to make port forward to external IP
edit
/etc/default/ufw
to accept forwarding requestsdefault_forward_policy = "accept"
edit /etc/ufw/sysctl.conf to allow forwarding
net.ipv4.ip_forward=1
edit
/etc/ufw/before.rules
, add the following after the first comment