iptables 如何限制IP的同时,又能完全允许往外发起请求呢?

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
回复
moliliang
帖子: 3
注册时间: 2014-08-24 22:59
系统: ubuntu 12.04

iptables 如何限制IP的同时,又能完全允许往外发起请求呢?

#1

帖子 moliliang » 2016-04-04 23:34

Hi,
新手,不太懂iptables,想问下如何限制IP访问的同时,不限制网络出口流量呢?

iptables -t filter -I INPUT 1 -s 123.123.123.123 -j ACCEPT
iptables -t filter -A INPUT -j DROP

比如这样是只允许 123.123.123.123 这个IP来访问。

但是会出现一个情况就是,我连ping(或者curl)其他网站都不行了(出的去,进不来)。。。

这个应该怎么整呢~~~
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: iptables 如何限制IP的同时,又能完全允许往外发起请求呢?

#2

帖子 poloshiao » 2016-04-05 5:43

新手
1. 安裝 Ubuntu 時 就預裝 ufw 防火牆 但是預設是 關閉的
看看 現況
sudo ufw status
2. 啟用
sudo ufw enable
sudo ufw status
3. 預設 封鎖進來
sudo ufw default deny
sudo ufw status
4. 允許 123.123.123.123 進來
sudo ufw allow from 123.123.123.123
sudo ufw status
5. 看看 能否使用 ping
6. 補充說明
6-1. ufw 是 iptables 的簡易前端程式 基於 iptables
6-2. ufw 只管進入 不管外出 意思是 外出 完全開放
6-3. 參閱
6-3-1. http://wiki.ubuntu.org.cn/index.php?tit ... nt=zh-hans
6-3-2. https://help.ubuntu.com/community/UFW
6-3-2. https://help.ubuntu.com/community/IptablesHowTo
7. gufw 是 ufw 的圖形前端 來自 universe 套件庫
moliliang
帖子: 3
注册时间: 2014-08-24 22:59
系统: ubuntu 12.04

Re: iptables 如何限制IP的同时,又能完全允许往外发起请求呢?

#3

帖子 moliliang » 2016-04-05 19:41

搞定了

iptables -t filter -A INPUT -m state --state NEW -d 123.123.123.123 -j DROP

禁止新的连接即可。
回复