如果脚本内有命令不能执行,需要自行安装,请根据实际端口名进行修改:
#!/bin/sh
#
# Do some initialzation for Rockchip Linux SDK....
#
case "$1" in
start)
ifconfig eth0 up
/run/swconfig dev switch0 set reset
/run/swconfig dev switch0 set apply
/run/swconfig dev switch0 set enable_vlan 1
/run/swconfig dev switch0 vlan 1 set ports "5t 0 1 2"
/run/swconfig dev switch0 vlan 2 set ports "5t 3"
/run/swconfig dev switch0 set apply
vconfig add eth0 1
vconfig add eth0 2
ifconfig eth0.1 down
ifconfig eth0.2 down
ip link set eth0.1 name lan
ip link set eth0.2 name wan
ifconfig lan up
ifconfig wan up
brctl addbr br0
brctl addif br0 lan
ifconfig br0 192.168.1.100 netmask 255.255.255.0
update-alternatives --set iptables /usr/sbin/iptables-legacy
ethList=`ls /sys/class/net|awk -F ' ' '{print $1}' | grep 'enx\|eth2'`
echo $ethList
iptables -t nat -A POSTROUTING -o wan -jMASQUERADE
iptables -A FORWARD -i lan -j ACCEPT
echo '1'>/proc/sys/net/ipv4/ip_forward
dnsmasq
;;
stop)
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
exit 0
DHCP部分用到了dnsmasq软件,配置文件/etc/dnsmasq.conf内容如下:
user=root interface=br0 dhcp-option=br0,1,255.255.255.0 #1表示为 子网掩码配置 dhcp-option=br0,3,192.168.1.100 #3表示为网关地址配置 dhcp-option=br0,6,192.168.1.100 #6表示为DNS地址配置 dhcp-range=br0,192.168.1.2,192.168.1.99,12h #配置范围和 DHCP租期长度
浙公网安备 33010602011771号