2025年5月27日星期二

Ubuntu24.04 服务器防火墙配置记录

 今天家里的服务器,SSH在日本可以成功访问,

在中国的内网中却访问不了。


查看下防火墙配置

sudo iptables -L -n -v

Chain INPUT (policy ACCEPT 43M packets, 81G bytes)

pkts bytes target prot opt in out source destination

0 0 ACCEPT 6 -- * * 192.168.3.223 0.0.0.0/0 tcp dpt:8888

34623 2312K ACCEPT 6 -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8888 -m geoip --source-country CN,JP

385 17628 DROP 6 -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8888 -m geoip ! --source-country CN,JP

0 0 ACCEPT 6 -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8888

Chain FORWARD (policy ACCEPT 27M packets, 23G bytes)

pkts bytes target prot opt in out source destination

Chain OUTPUT (policy ACCEPT 40M packets, 71G bytes)

pkts bytes target prot opt in out source destination

root@linux:~#


想起来之前配置了防火墙规则,允许CN和JP的IP访问,并且只允许了
内网的192.168.3.223一台主机访问。

这下好办了,把192.168.3.0/24整个子网全部允许
sudo iptables -I INPUT -p tcp -s 192.168.3.0/24 --dport 8888 -j ACCEPT

root@linux:~# sudo iptables -L -n -v
Chain INPUT (policy ACCEPT 43M packets, 81G bytes)
 pkts bytes target     prot opt in     out     source               destination
   38  7792 ACCEPT     6    --  *      *       192.168.3.0/24       0.0.0.0/0            tcp dpt:8888
    0     0 ACCEPT     6    --  *      *       192.168.3.223        0.0.0.0/0            tcp dpt:8888
34629 2312K ACCEPT     6    --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8888 -m geoip --source-country CN,JP
  385 17628 DROP       6    --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8888 -m geoip ! --source-country CN,JP
    0     0 ACCEPT     6    --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8888

Chain FORWARD (policy ACCEPT 27M packets, 23G bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 40M packets, 71G bytes)
 pkts bytes target     prot opt in     out     source               destination
root@linux:~#


配置成功,保存配置
sudo netfilter-persistent save

测试,内网的另外一台电脑SSH成功登录。

对了,把以前那条老的规则应该删掉
sudo iptables -D INPUT -p tcp -s 192.168.3.223 --dport 8888 -j ACCEPT

sudo iptables -L -n -v

Chain INPUT (policy ACCEPT 43M packets, 82G bytes)
 pkts bytes target     prot opt in     out     source               destination
   44  8176 ACCEPT     6    --  *      *       192.168.3.0/24       0.0.0.0/0            tcp dpt:8888
34662 2315K ACCEPT     6    --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8888 -m ge                                                                                                                                                                                   oip --source-country CN,JP
  385 17628 DROP       6    --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8888 -m ge                                                                                                                                                                                   oip ! --source-country CN,JP
    0     0 ACCEPT     6    --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8888

Chain FORWARD (policy ACCEPT 27M packets, 23G bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 40M packets, 71G bytes)
 pkts bytes target     prot opt in     out     source               destination
root@linux:~#

成功,保存。
sudo netfilter-persistent save




 


没有评论:

发表评论

XG-040G-XX SuPassword 解密工具

 买了新光猫 XG-040G-TF ,  所以写了一个 SuPassword 解密工具, 以备不时之需 . 点击下载