2.7. Blocking Access from a Remote Host
Problem
You want to block incoming traffic from a particular host.
Solution
To block all access by that host:
For
iptables
:
# iptables -A INPUT -s remote_IP_address
-j REJECT
For
ipchains
:
# ipchains -A input -s remote_IP_address
-j REJECT
To block requests for one particular service, say, the SMTP mail service:
For
iptables
:
# iptables -A INPUT -p tcp -s remote_IP_address
--dport smtp -j REJECT
For
ipchains
:
# ipchains -A input -p tcp -s remote_IP_address
--dport smtp -j REJECT
To admit some hosts but block all others:
For
iptables
:
# iptables -A INPUT -sIP_address_1
[-pprotocol
--dportservice
] -j ACCEPT # iptables -A INPUT -sIP_address_2
[-pprotocol
--dportservice
] -j ACCEPT # iptables -A INPUT -sIP_address_3
[-pprotocol
--dportservice
] -j ACCEPT # iptables -A INPUT [-pprotocol
--dportservice
] -j REJECT
For
ipchains
:
# ipchains -A input -sIP_address_1
[-pprotocol
--dportservice
] -j ACCEPT # ipchains -A input -sIP_address_2
[-pprotocol
--dportservice
] -j ACCEPT # ipchains -A input -sIP_address_3
[-pprotocol
--dportservice
] -j ACCEPT # ipchains -A input [-pprotocol
--dportservice
] -j REJECT
Discussion
You can also block access at other levels such as TCP-wrappers. [Recipe 3.9][Recipe 3.11]
See Also
iptables(8), ipchains(8).
Get Linux Security Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.