services-xbee_net/scripts/setup_host_device.sh

46 lines
2.0 KiB
Bash

# Enable IP forwarding
sudo sysctl \
-w # Write (or set) the value of a kernel parameter
net.ipv4.ip_forward=1 # Temporarily enable IP forwarding to forward network packets from one network interface to another
# Configure NAT for the bridge
sudo iptables \
-t nat # Specify the nat table used for Network Address Translation
-A POSTROUTING # Append this rule to the POSTROUTING chain, which alters packets as they are about to leave the network interface
-o wlp0s20f3 # Apply this rule to packets leaving the wlp0s20f3 interface (Wi-Fi interface)
-j MASQUERADE # Use the MASQUERADE target to change the source IP address to the IP address of the outgoing interface, enabling multiple devices on a private network to share a single public IP address
# Configure xbnet and bridge interfaces
sudo xbnet \
/dev/ttyUSB0 \ # Port where the XBee device is connected
tun # Create a TUN (network tunnel) interface for routing IP packets
sudo ip addr \
add 192.168.100.1/24 \ # Assign the IP address 192.168.100.1 with a subnet mask of 255.255.255.0
dev xbnet0 # to the xbnet0 interface
sudo ip link \
set dev xbnet0 up # Activate the xbnet0 interface
sudo brctl \
addbr br0 # Create a new bridge interface named br0
sudo brctl \
addif br0 wlp0s20f3 # Add the Wi-Fi interface wlp0s20f3 to the bridge br0
sudo brctl \
addif br0 xbnet0 # Add the xbnet0 interface to the bridge br0
sudo ip link \
set dev br0 up # Activate the bridge interface br0
sudo ip addr \
flush dev wlp0s20f3 # Remove any IP addresses assigned to the wlp0s20f3 interface
sudo ip addr \
add 192.168.7.122/24 \ # Assign the IP address 192.168.7.122 with a subnet mask of 255.255.255.0
dev br0 # to the bridge interface br0
sudo ip link \
set dev wlp0s20f3 up # Reactivate the wlp0s20f3 interface