脚本如下。
#!/bin/bash
MEMLOG="/run/media/mmcblk1p1/3568/laohua/memlog.txt"
RED=$(echo -en '\033[00;31m')
RESTORE=$(echo -en '\033[0m')
touch ${MEMLOG}
ifconfig eth0 down
ifconfig eth1 down
ip route | awk '{print $1}' | while read line; do ip route del $line; done
sleep 1
/sbin/ifconfig eth0 hw ether 7A:B8:66:57:39:2B
/sbin/ifconfig eth1 hw ether 7A:B8:66:57:39:2C
/sbin/ifconfig eth0 up
/sbin/ifconfig eth1 up
sleep 1
/sbin/ifconfig eth0 192.168.1.1 netmask 255.255.255.0
/sbin/ifconfig eth1 192.168.1.2 netmask 255.255.255.0
/sbin/route add 192.168.1.11 dev eth0
/sbin/route add 192.168.1.22 dev eth1
sleep 1
/sbin/arp -i eth0 -s 192.168.1.11 7A:B8:66:57:39:2C
/sbin/arp -i eth1 -s 192.168.1.22 7A:B8:66:57:39:2B
/usr/sbin/iptables -t nat -F
/usr/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.1 -d 192.168.1.11 -j SNAT --to-source 192.168.1.22
/usr/sbin/iptables -t nat -A PREROUTING -s 192.168.1.22 -d 192.168.1.11 -j DNAT --to-destination 192.168.1.2
/usr/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.2 -d 192.168.1.22 -j SNAT --to-source 192.168.1.11
/usr/sbin/iptables -t nat -A PREROUTING -s 192.168.1.11 -d 192.168.1.22 -j DNAT --to-destination 192.168.1.1
iperf3 -p 5201 -s &
iperf3 -p 5201 -c 192.168.1.11 -i 5 -t 60000
iperf3 -p 5201 -c 192.168.1.22 -i 5 -t 60000
脚本执行没有问题,都正常,就是不知道后面的几行就是
/sbin/arp -i eth0 -s 192.168.1.11 7A:B8:66:57:39:2C
/sbin/arp -i eth1 -s 192.168.1.22 7A:B8:66:57:39:2B
/usr/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.1 -d 192.168.1.11 -j SNAT --to-source 192.168.1.22
/usr/sbin/iptables -t nat -A PREROUTING -s 192.168.1.22 -d 192.168.1.11 -j DNAT --to-destination 192.168.1.2
/usr/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.2 -d 192.168.1.22 -j SNAT --to-source 192.168.1.11
/usr/sbin/iptables -t nat -A PREROUTING -s 192.168.1.11 -d 192.168.1.22 -j DNAT --to-destination 192.168.1.1
有能给详细解释一下的吗,谢谢。