linux防火墙配置


查看防火墙配置
# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

为了在打开防火墙时不影响ssh连接,所以先设置ssh端口,默认为22
# iptables -A INPUT -p tcp -d 10.0.0.8 --dport 2222 -j ACCEPT
# iptables -A OUTPUT -p tcp -s 10.0.0.8 --sport 2222 -j ACCEPT

打开防火墙
# iptables -P INPUT DROP
# iptables -P OUTPUT DROP
# iptables -P FORWARD DROP

# iptables -L -n
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            10.0.0.8            tcp dpt:2222

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  10.0.0.8             0.0.0.0/0           tcp spt:2222

打开80端口
# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# iptables -A OUTPUT -p tcp  --sport 80 -j ACCEPT

# iptables -L -n --line-numbers
Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            10.0.0.8            tcp dpt:2222
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80

Chain FORWARD (policy DROP)
num  target     prot opt source               destination

Chain OUTPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  10.0.0.8             0.0.0.0/0           tcp spt:2222
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:80

保存配置,两种方法,选其一就可以了
# service iptables save
# iptables-save > /etc/sysconfig/iptables

大部分的DNS服务都是使用UDP的
# iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
# grep domain /etc/services
domain          53/tcp                          # name-domain server
domain          53/udp
domaintime      9909/tcp                        # domaintime
domaintime      9909/udp                        # domaintime

# iptables -A INPUT -p udp --sport 53 -j ACCEPT

自己的DNS指向自己时,即既是客户机又是服务器,需要在链上增加两个条件
# iptables -A INPUT -p udp --dport 53 -j ACCEPT
# iptables -A OUTPUT -p udp --sport 53 -j ACCEPT

# iptables -D OUTPUT 5

# netstat -tnl
因为考虑到,不打开会影响内部服务器的正常运行,也不会给服务器造成什么危害
# iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
# ^IN^OUT
iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT

# iptables -A OUTPUT -p tcp --sport 2222 -m state --state ESTABLISHED -j ACCEPT
# iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
两次执行以下命令,删除以前两个设置
# iptables -D OUTPUT 1

# iptables -A OUTPUT -p tcp --dport 2222 -j ACCEPT
# iptables -A INPUT -p tcp --sport 2222 -m state --state ESTABLISHED -j ACCEPT

直接打开3306端口
# iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
# iptables -A OUTPUT -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT

 

 


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值