1、拒绝所有主机ping当前的主机。
[root@CentOS8 ~]# iptables -A INPUT -p icmp --icmp-type 8 -j REJECT
2、本机能够访问别的机器的HTTP服务,但是别的机器无法访问本机。
[root@CentOS8 ~]# iptables -A INPUT -d 10.0.0.8 -p tcp --dport 80 -j REJECT
10.0.0.8为本机IP
3、当我们发现有 ip 恶意攻击我们得时候,我们可以通过对防火墙设定规则来进行控制。所以我们可以添加connlimit模块来实现对最大并发的控制。请写出步骤
[root@CentOS8 ~]# iptables -A INPUT -d 10.0.0.8 -p tcp --dport 22 -m connlimit --connlimit-above 2 -j REJECT
10.0.0.8为本机IP
22为使用ssh访问我们的端口
2是最大并发连接数量
4、实践题
实验前提需求
现在我在外地出差使用A7互联网主机,但是现在由于公司有业务需要我 ssh 链接到内网、这时候我就联系我们公司同事在防火墙上配置相关规则让我链接进公司内网
请写出实现过程:
#A8启用路由转发
[root@A8 ~]#vim /etc/sysctl.conf
net.ipv4.ip_forward=1
[root@A8 ~]#sysctl -p
配置NAT规则
[root@A8 ~]# iptables -t nat -A PREROUTING -d 192.168.1.129 -p tcp --dport 22 -j DNAT --to-destination 10.0.0.18
[root@A8 ~]# iptables -vnL -t nat
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 DNAT tcp -- * * 0.0.0.0/0 192.168.1.129 tcp dpt:22 to:10.0.0.18
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
其中192.168.1.129是互联网(公网)地址,10.0.0.18是局域网服务器地址
#结果验证
[root@A7 ~]# ssh 192.168.1.129 -->这里使用互联网(公网)地址
The authenticity of host '192.168.1.129 (192.168.1.129)' can't be established.
RSA key fingerprint is f8:8e:3b:d5:9d:c6:32:22:98:71:e4:d9:d9:ac:9b:26.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.129' (RSA) to the list of known hosts.
root@192.168.1.129's password:
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Sat Sep 19 18:31:49 2020 from 192.168.1.128
[root@B8 ~]# -->自动跳转至局域网服务器