Linux服务器中怎么设置一个端口只能一个IP访问。需要建策略规则么?

现在需要在Linux服务器中的1521端口只允许一个IP访问,请讲一下具体的配置参数和条目,谢谢。

Linux防火墙Iptable如何设置只允许某个ip访问80端口,只允许特定ip访问某端口?参考下面命令,只允许46.166.150.22访问本机的80端口。如果要设置其他ip或端口,改改即可。
iptables -I INPUT -p TCP --dport 80 -j DROP
iptables -I INPUT -s 46.166.150.22 -p TCP --dport 80 -j ACCEPT
在root用户下执行上面2行命令后,重启iptables, service iptables restart
查看iptables是否生效:
[root@xxxx]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 46.166.150.22 anywhere tcp dpt:http
DROP tcp -- anywhere anywhere tcp dpt:http

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
上面命令是针对整个服务器(全部ip)禁止80端口,如果只是需要禁止服务器上某个ip地址的80端口,怎么办?
下面的命令是只允许来自174.140.3.190的ip访问服务器上216.99.1.216的80端口
iptables -A FORWARD -s 174.140.3.190 -d 216.99.1.216 -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A FORWARD -d 216.99.1.216 -p tcp -m tcp --dport 80 -j DROP
如果您不熟悉linux的ssh命令,那么可以在webmin/virtualmin面板中设置,达到相同效果。参考:webmin面板怎样设置允许特定ip访问80端口,禁止80端口

更多iptables参考命令如下:
1.先备份iptables

# cp /etc/sysconfig/iptables /var/tmp

需要开80端口,指定IP和局域网

下面三行的意思:

先关闭所有的80端口

开启ip段192.168.1.0/24端的80口

开启ip段211.123.16.123/24端ip段的80口

# iptables -I INPUT -p tcp --dport 80 -j DROP
# iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT
# iptables -I INPUT -s 211.123.16.123/24 -p tcp --dport 80 -j ACCEPT

以上是临时设置。

2.然后保存iptables

# service iptables save

3.重启防火墙

#service iptables restart
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答