gns3-registry/packer/tinycore-linux/scripts/internet.sh
Julien Duponchelle d1e1c8e2bb Internet appliance
2015-10-28 15:28:24 +01:00

47 lines
1.3 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

set -x
# Enable NAT
echo "iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE" >> /opt/bootlocal.sh
echo "iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT" >> /opt/bootlocal.sh
echo "iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT" >> /opt/bootlocal.sh
tce-load -wi dnsmasq
# Setup DHCP
# A random IP range is choose at startup allowing user to put multiple access links
cat > setup_dhcp_and_ip.sh << 'EOF2'
#!/bin/sh
killall udhcpc
killall udhcpd
killall dnsmasq
udhcpc -i eth1
IP=$((RANDOM%253+1))
ifconfig eth0 172.16.$IP.1 netmask 255.255.255.0 up
echo "expand-hosts" >> /etc/dnsmasq.conf
echo "no-negcache" >> /etc/dnsmasq.conf
echo "dhcp-authoritative" >> /etc/dnsmasq.conf
echo "dhcp-leasefile=/tmp/dhcp.leases" >> /etc/dnsmasq.conf
echo "dhcp-range=172.16.$IP.2,172.16.$IP.254,12h" >> /etc/dnsmasq.conf
echo "# Netmask" >> /etc/dnsmasq.conf
echo "dhcp-option=1,255.255.255.0" >> /etc/dnsmasq.conf
echo "# Route" >> /etc/dnsmasq.conf
echo "dhcp-option=3,172.16.$IP.1" >> /etc/dnsmasq.conf
dnsmasq
EOF2
sudo mv setup_dhcp_and_ip.sh /sbin/setup_dhcp_and_ip.sh
sudo chmod 700 /sbin/setup_dhcp_and_ip.sh
sudo chown root /sbin/setup_dhcp_and_ip.sh
echo '/sbin/setup_dhcp_and_ip.sh' >> /opt/bootlocal.sh
echo 'etc/dnsmasq.conf' >> /opt/.filetool.lst
echo 'sbin/setup_dhcp_and_ip.sh' >> /opt/.filetool.lst