12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#!/bin/bash# Script to set up network sharing with static IP# Define network interfaces and IP addressesLAN_INTERFACE="eth0"WIFI_INTERFACE="wlan0"LAN_IP="192.168.0.1"DHCP_RANGE="192.168.0.10,192.168.0.50,12h"# Enable IP forwardingsysctl net.ipv4.ip_forward=1# Set up iptables rulesiptables -A POSTROUTING -t nat -o $WIFI_INTERFACE -j MASQUERADEiptables -A FORWARD -i $WIFI_INTERFACE -o $LAN_INTERFACE -m state --state RELATED,ESTABLISHED -j ACCEPTiptables -A FORWARD -i $LAN_INTERFACE -o $WIFI_INTERFACE -j ACCEPT# Start dnsmasqservice dnsmasq startservice dnsmasq restart# Save iptables rulesiptables-save | tee /etc/iptables.rules# Configure static IP for LAN interfaceifconfig $LAN_INTERFACE $LAN_IPecho "interface $LAN_INTERFACE" >> /etc/dnsmasq.confecho "dhcp-range=$LAN_IP,$DHCP_RANGE" >> /etc/dnsmasq.conf 注意端口占用,需要kill