防火墙放行全部端口
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
或者直接删除规则
rm -rf /etc/iptables/rules.v4
rm -rf /etc/iptables/rules.v6
直接删除省事,如果是选择放行端口的话,需要保存修改到文件,不然重启会失效,要么 apt-get purge iptables-persistent(不要直接用 remove);
Ubuntu/Debian 保存修改的 iptables 规则:
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
个人选择:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
顺便把开启 root 密码登录以及更改 ssh 端口方法也贴这吧:
修改 root 密码,把下面的”密码“替换成你的密码,注意”root: 密码“的冒号之后一定不要有空格,比如 root:passwd.hostloc
echo root: 密码 |sudo chpasswd root
或者直接使用 passwd 修改密码
开启 root 密码登录
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
修改 ssh 端口,假设改 ssh 端口为 65522(可以直接在 /etc/ssh/sshd_config 中添加 Port 65522,如果没把握,把 Port 22(默认一般是注释的)也加上,重启后没问题再注释掉# Port 22)
sed -i 's/#Port 22/Port 65522/' /etc/ssh/sshd_config
重启 sshd 服务
service ssh restart
检查监听的端口
netstat -antp |grep ssh
========================================================
如果没把握,再处理一遍防火墙
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
正文完