Posts

Showing posts with the label Iptables

Can I Use Ufw To Setup A Port Forward?

Answer : Solution 1: Let's say you want to forward requests going to 80 to a server listening on port 8080. Note that you will need to make sure port 8080 is allowed, otherwise ufw will block the requests that are redirected to 8080. sudo ufw allow 8080/tcp There are no ufw commands for setting up the port forwards, so it must be done via configuraton files. Add the lines below to /etc/ufw/before.rules , before the filter section, right at the top of the file: *nat :PREROUTING ACCEPT [0:0] -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 COMMIT Then restart and enable ufw to start on boot: sudo ufw enable Solution 2: Since ufw 0.34 ufw supports forward rules. example: sudo ufw route allow in on eth0 out on eth1 to 10.0.0.0/8 port 8080 from 192.168.0.0/16 port 80 You also need to make sure you have the sysctl net.ipv4.ip_forward enabled. For most distributions, that's done by editing /etc/sysctl.conf and running sysctl -p or rebooting....

Centos 7 Save Iptables Settings

Answer : Solution 1: Disable firewalld by the following command: systemctl disable firewalld Then install iptables-service by following command: yum install iptables-services Then enable iptables as services: systemctl enable iptables Now you can save your iptable rules by following command: service iptables save Solution 2: CentOS 7 is using FirewallD now! Use the --permanent flag to save settings. Example: firewall-cmd --zone=public --add-port=3000/tcp --permanent Then reload rules: firewall-cmd --reload Solution 3: On CentOS 7 Minimal you may need to install the iptables-services package (thanks to @RichieACC for the suggestion): sudo yum install -y iptables-services And then enable the service using systemd : sudo systemctl enable iptables.service And run the initscript to save your firewall rules: sudo /usr/libexec/iptables/iptables.init save Solution 4: iptables-save > /etc/sysconfig/iptables will save the current configuration wi...