(一般情况,ubuntu安装好的时候,iptables会被安装上),使用以下命令:
sudo apt update
sudo apt install iptables
用命令开放端口:
sudo iptables -I INPUT -p tcp --dport 8888 -j ACCEPT
sudo iptables-save
iptables -L -n
service iptables restart
(Ubuntu 16.04下iptables打开端口并重启后自动生效)
sudo apt install iptables-persistent
sudo netfilter-persistent save
sudo netfilter-persistent reload
开机启动脚本/etc/rc.local
sudo vim /etc/rc.local
#!/bin/sh -e #rc.local sudo netfilter-persistent reload echo "开机启动iptables" >> /usr/local/rc.log exit 0