vi /usr/local/sbin/iptables.sh //加入以下內容 ######編輯的內容以下######## #! /bin/bash ipt=「/usr/sbin/iptables」 //定義一個變量,要寫絕對路徑 $ipt –F // 清空以前的規則 $ipt -P INPUT DROP //定義一些策略 $ipt -P OUTPUT ACCEPT $ipt -P FORWARD ACCEPT $ipt -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT //增長規則,指定狀態放行 $ipt -A INPUT -s 192.168.133.0/24 -p tcp --dport 22 -j ACCEPT $ipt -A INPUT -p tcp --dport 80 -j ACCEPT $ipt -A INPUT -p tcp --dport 21 -j ACCEPT 指定端口放行
iptables -I INPUT -p icmp --icmp-type 8 -j DROP
**A機器兩塊網卡ens33(192.168.10.129)、ens37(192.168.110.110),ens33能夠上外網,ens37僅僅是內部網絡,
B機器只有en s37(192.168.110.90),和A機器ens37能夠通訊互聯。** - 注意:兩個網卡ip的寫法 ,是與自己網卡不一樣網段,新增網卡相同的網段html
[root@centos001 ~]# cat /proc/sys/net/ipv4/ip [root@centos001 ~]# cat /proc/sys/net/ipv4/ip ip_default_ttl ipfrag_max_dist ip_dynaddr ipfrag_secret_interval ip_early_demux ipfrag_time ip_forward ip_local_port_range ip_forward_use_pmtu ip_local_reserved_ports ipfrag_high_thresh ip_nonlocal_bind ipfrag_low_thresh ip_no_pmtu_disc [root@centos001 ~]# cat /proc/sys/net/ipv4/ip_forward 0 [root@centos001 ~]# echo "1" > !$ echo "1" > /proc/sys/net/ipv4/ip_forward [root@centos001 ~]# !cat cat /proc/sys/net/ipv4/ip_forward 1
[root@centos001 ~]# iptables -t nat -A POSTROUTING -s 192.168.110.0/24 -o ens33 -j MASQUERADE [root@centos001 ~]# iptables -t nat -nvL Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain INPUT (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 Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 MASQUERADE all -- * ens33 192.168.100.0/24 0.0.0.0/0 //最下能看到咱們增長的規則