ubuntu 14下iptables 简易教程 2016.2

iptable 官方指南

#sudo iptables -LList 列出所有规则

可以看到类似这样的界面

(--如果已经存在规则 # sudo iptables -F Flush清掉所有规则

# sudo iptables -X清掉用户定义的规则

# sudo iptables -Z--)

-----------------------------------------------------------------

Chain INPUT (policy ACCEPT)

target protopt sourcedestination


Chain FORWARD (policy ACCEPT)

target protopt sourcedestination


Chain OUTPUT (policy ACCEPT)

target protopt sourcedestination

----------------------------------------------------------------------

分为三块:INPUT,FORWARD,OUTPUT

修改默认策略 -P change Policy on chain

# sudo iptables -P INPUT DROP

# sudo iptables -P FORWARD DROP

# sudo iptables -P OUTPUT ACCEPT


开放服务对应端口

-A Append添加规则 -p 协议protocal -dport 目标端口destination port -j 目标

# sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

# sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT


允许loopback -i 网络端口interface

# sudo iptables -A INPUT -i lo -p all -j ACCEPT


允许已经建立的和相关的连接(很重要,如果使用机器上网必须输入这条)

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


保存设置

# sudo iptables-save > /etc/iptables.rules

为使开机启动网络时就使用以上设置。

# sudo vi /etc/network/interfaces

添加以下语句

pre-up iptables-restore </etc/iptables.rules


最后是这样的

-----------------------------------------------------------------

Chain INPUT (policy DROP)

target protopt sourcedestination

ACCEPT all-- anywhereanywhere state RELATED,ESTABLISHED

ACCEPT tcp --anywhere anywheretcp dpt:ssh

ACCEPT tcp--anywhereanywheretcpdpt:http

ACCEPTall -- anywhere anywhere


Chain FORWARD (policy DROP)

target protopt sourcedestination


Chain OUTPUT (policy ACCEPT)

target protopt sourcedestination

----------------------------------------------------------------------



如果觉得命令行麻烦,可以使用gufw: Graphic Uncomplicated FireWall 官方指南

# sudo apt-get install gufw

系统设置里Firewall configuration 很容易使用



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值