linux防火墙添加白名单命令,Linux 下设置防火墙白名单

以211为例:标红为修改部分

1、编辑防火墙配置文件

指定192.168.8.212可以通过22端口连接

# vi /etc/sysconfig/iptables

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-N whitelist

-A whitelist -s 192.168.8.212 -j ACCEPT

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

#-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j whitelist

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

2、重启防火墙

# service iptables restart

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Unloading modules:                               [  OK  ]

iptables: Applying firewall rules:                         [  OK  ]

[root@hadoop211 sysconfig]# service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0

3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

4    whitelisttcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22

5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

num  target     prot opt source               destination

1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num  target     prot opt source               destination

Chain whitelist (1 references)

num  target     prot opt source               destination

1    ACCEPT     all  --  192.168.8.212        0.0.0.0/0

3、连接测试

192.168.8.212上:可以连接

[root@bdc212 ~]# ssh 192.168.8.211

root@192.168.8.211's password:

Last login: Thu Jun 23 11:17:08 2016 from hadoop212

[root@hadoop211 ~]#

192.168.8.213上:则不可以连接

[root@bdc213 ~]# ssh 192.168.8.211

ssh: connect to host 192.168.8.211 port 22: No route to host

参考链接:

http://blog.csdn.net/catoop/article/details/50476099

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值