大网数据广告活动
服务器运维问答

New chain for specific IP iptables

· 52CE 我爱测

I need to create a new chain to treat a specific IP, say 192.168.0.101. In this new chain, this IP will have access to all services, except FTP. My solution is: iptables -N IP1 iptables -A IP1 -p tcp --dport 20 -j DROP iptables -…

问题原文

原帖链接 · Bruno A · CC BY-SA 3.0

I need to create a new chain to treat a specific IP, say 192.168.0.101.

In this new chain, this IP will have access to all services, except FTP.

My solution is:

iptables -N IP1

iptables -A IP1 -p tcp --dport 20 -j DROP
iptables -A IP1 -p tcp --dport 21 -j DROP
iptables -A IP1 -j ACCEPT

iptables -A INPUT -s 192.168.0.101 -j IP1

Is the solution correct? Does two rules with --sport 20, 21 are required for incoming packets?

已采纳解答

原帖链接 · Zoredache · CC BY-SA 3.0

Your suggested rules should work, but there may be cases where a DROP in a chain is not the correct action.

For example if you wanted some later rule INPUT chain to permit ftp access to some specific destination for all hosts on your network.

In this case a RETURN might be a better choice. Assuming the policy of your INPUT chain is DROP this would probably also have the same results.

iptables -A IP1 -p tcp --dport 20 -j RETURN
iptables -A IP1 -p tcp --dport 21 -j RETURN
iptables -A IP1 -j ACCEPT

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。