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 //最下能看到咱们增长的规则