Гоняю двухпортовые сетевые карты, залупленные один порт в другой патч-кордом. Использую скрипт, в котором через tmux организован запуск клиента и сервера в одном окне терминала.
Хотел бы упростить все и не использовать tmux. Подскажите вариант. Попробовал parallel но что-то не получилось(
Сам скрипт: (markdown не срабатывает почему-то)
#!/bin/bash
# Set interface names and IP addresses.
intf_server="ens8f0"
intf_client="ens8f2"
timeout=20
ip_server="10.1.1.1"
ip_client="10.1.1.2"
ipfake_server="10.2.1.1"
ipfake_client="10.2.1.2"
port=5201
# Set MAC addresses
mac_server=`ip link show dev ${intf_server} | grep link/ether | awk '{print $2}'`
mac_client=`ip link show dev ${intf_client} | grep link/ether | awk '{print $2}'`
# Set up network interfaces
sudo ip address add ${ip_server}/30 dev ${intf_server}
sudo ip address add ${ip_client}/30 dev ${intf_client}
sudo ip link set dev ${intf_server} mtu 9000
sudo ip link set dev ${intf_client} mtu 9000
sudo ip link set dev ${intf_server} up
sudo ip link set dev ${intf_client} up
# Set up NAT rules
# nat source IP ${IP_0} -> ${FAKE_0} when going to ${FAKE_1}
sudo iptables -t nat -A POSTROUTING -s ${ip_client} -d ${ipfake_server} -j SNAT --to-source ${ipfake_client}
# nat inbound ${FAKE_0} -> ${IP_0}
sudo iptables -t nat -A PREROUTING -d ${ipfake_client} -j DNAT --to-destination ${ip_client}
# nat source IP ${IP_1} -> ${FAKE_1} when going to ${FAKE_0}
sudo iptables -t nat -A POSTROUTING -s ${ip_server} -d ${ipfake_client} -j SNAT --to-source ${ipfake_server}
# nat inbound ${FAKE_1} -> ${IP_1}
sudo iptables -t nat -A PREROUTING -d ${ipfake_server} -j DNAT --to-destination ${ip_server}
# Set up routing and ARP tables
sudo ip route add ${ipfake_server} dev ${intf_client}
sudo arp -i ${intf_client} -s ${ipfake_server} ${mac_server}
sudo ip route add ${ipfake_client} dev ${intf_server}
sudo arp -i ${intf_server} -s ${ipfake_client} ${mac_client}
# Start iperf3 server in a tmux window
tmux start-server
tmux new-session -s iperf3run1 -n iperf3:0 -d "iperf3 -s -B ${ip_server} -p ${port}"
# Start iperf3 client in a tmux window
tmux new-window -n iperf3:1 -t iperf3run1: "iperf3 -c ${ipfake_server} -B ${ip_client} -t ${timeout} -b 0 -p ${port} --bidir"
tmux attach
# Clean up NAT rules, routing and ARP tables
sudo iptables -t nat -F
sudo ip route del ${ipfake_server} dev ${intf_client}
sudo arp -d ${ipfake_server}
sudo ip route del ${ipfake_client} dev ${intf_server}
sudo arp -d ${ipfake_client}
sudo ip address del ${ip_server}/30 dev ${intf_server}
sudo ip address del ${ip_client}/30 dev ${intf_client}
sudo ip link set dev ${intf_server} mtu 1500
sudo ip link set dev ${intf_client} mtu 1500
# kill iperf3
pkill -f iperf3
exit 0