We often need to impose some security restrictions when configuring the linux server, such as only allowing specific IP address segments to access the specified port. For example, I have a server with dual-IP addresses that can be accessed from both internal and external networks, but some applications do not allow access from external users. Therefore, some special restrictions must be imposed on the port, for example, to allow only users in the 192.168.1.x CIDR block to access port 389 of the server, we can add the following settings in the server's iptables:
- -A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp-s 192.168.1.0/24 -- dport389-j ACCEPT
Use-s to specify the source address. Here, only machines in the 192.168.1.x network segment can access the specified port 389 (specified through-dport), and then restart the firewall.
- Service iptables restart
Then, we can smoothly access port 389 through the Intranet, and machines in the external network or outside the network segment will not be able to access the port, thus achieving the desired effect, security restrictions are imposed.