Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iptables #182

Open
bingoogolapple opened this issue Jul 27, 2017 · 9 comments
Open

iptables #182

bingoogolapple opened this issue Jul 27, 2017 · 9 comments
Labels

Comments

@bingoogolapple
Copy link
Owner

  • 四张表:filter、nat、mangle、raw
  • 五条链:INPUT OUTPUT FORWARD PREROUTING POSTROUTING

image
image
image

@bingoogolapple
Copy link
Owner Author

bingoogolapple commented Jul 27, 2017

列出之前设置的规则

iptables -nL

清除之前设置的规则

iptables -F

允许 22 端口的访问「一定要设置该端口允许被访问,否则设置 iptables 后外部机器没法连接到这台服务器(如果这台服务器 sshd 端口是 22 的话)」

iptables -I INPUT -p tcp --dport 22 -j ACCEPT

允许 80 端口的访问

iptables -I INPUT -p tcp --dport 80 -j ACCEPT

允许一段端口 10 - 21 被访问

iptables -I INPUT -p tcp --dport 10:21 -j ACCEPT

允许所有 icmp 协议被访问

iptables -I INPUT -p icmp -j ACCEPT

在 iptables 的最后添加一条规则,拒绝所有「-I 是在最前面添加规则,-A 是在最后面添加规则」

iptables -A INPUT -j REJECT

删除 80 端口的访问规则

iptables -D INPUT -p tcp --dport 80 -j ACCEPT

拒绝 80 端口被访问

iptables -I INPUT -p tcp --dport 80 -j REJECT

允许所有通过 lo 设备过来的数据包,否则本机无法访问本机

iptables -I INPUT -i lo -j ACCEPT

允许本机访问其他主机

iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

只允许 10.103.188.233 访问本机 httpd 服务

iptables -D INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp -s 10.103.188.233 --dport 80 -j ACCEPT

@bingoogolapple
Copy link
Owner Author

端口扫描

nmap -sS -p 0-1000 10.10.163.233

@bingoogolapple
Copy link
Owner Author

bingoogolapple commented Jul 29, 2017

image
image
image

@bingoogolapple
Copy link
Owner Author

iptables -F

iptables -I INPUT -i lo -j ACCEPT
iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A INPUT -s 10.10.155.0/24 -j ACCEPT
iptables -A INPUT -s 10.10.188.0/24 -j ACCEPT
iptables -A INPUT -s 10.10.140.0/24 -j ACCEPT

iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 1723 -j ACCEPT

iptables -I INPUT -p icmp -j ACCEPT

iptables -A INPUT -j REJECT

@bingoogolapple
Copy link
Owner Author

bingoogolapple commented Jul 29, 2017

保存 iptables 配置到文件「/etc/sysconfig/iptables」中

/etc/init.d/iptables save
chkconfig iptables on

@bingoogolapple
Copy link
Owner Author

bingoogolapple commented Jul 29, 2017

image

iptables -t nat -A POSTROUTING -s 10.10.177.0/24 -j SNAT --to 10.10.188.232

@bingoogolapple
Copy link
Owner Author

bingoogolapple commented Jul 29, 2017

image

iptables -t nat -A PREROUTING -d 10.10.188.232 -p tcp --dport 80 -j DNAT --to 10.10.177.233:80

@bingoogolapple
Copy link
Owner Author

bingoogolapple commented Jul 29, 2017

限制每一个客户端 ip 的并发连接数

iptables -I INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 100 -j REJECT

10 个以内放行,超过 10 的话就每一分钟只允许 1 个

iptables -A INPUT -p icmp -m limit --limit 1/m --limit-burst 10 -j ACCEPT
iptables -A INPUT -p icmp -j REJECT

@bingoogolapple
Copy link
Owner Author

image
image
image
image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant