2 #============================================================================
3 # Default Xen network start/stop script when using NAT.
4 # Xend calls a network script when it starts.
5 # The script name to use is defined in /etc/xen/xend-config.sxp
6 # in the network-script field.
10 # network-nat (start|stop|status) {VAR=VAL}*
14 # netdev The gateway interface (default eth0).
15 # antispoof Whether to use iptables to prevent spoofing (default no).
16 # dhcp Whether to alter the local DHCP configuration (default no).
18 #============================================================================
21 . "$dir/xen-script-common.sh"
22 . "$dir/xen-network-common.sh"
27 netdev=${netdev:-eth0}
28 # antispoofing not yet implemented
29 antispoof=${antispoof:-no}
31 # turn on dhcp feature by default if dhcpd is installed
32 if [ -f /etc/dhcpd.conf ]
40 if [ "$dhcp" != 'no' ]
42 dhcpd_conf_file=$(find_dhcpd_conf_file)
43 dhcpd_init_file=$(find_dhcpd_init_file)
44 if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ]
46 echo 'Failed to find dhcpd configuration or init file.' >&2
54 if ! grep -q "subnet 10.0.0.0" "$dhcpd_conf_file"
56 echo >>"$dhcpd_conf_file" "subnet 10.0.0.0 netmask 255.255.0.0 {}"
59 "$dhcpd_init_file" restart
65 local tmpfile=$(mktemp)
66 grep -v "subnet 10.0.0.0" "$dhcpd_conf_file" >"$tmpfile"
67 if diff "$tmpfile" "$dhcpd_conf_file" >&/dev/null
71 mv "$tmpfile" "$dhcpd_conf_file"
74 "$dhcpd_init_file" restart
79 echo 1 >/proc/sys/net/ipv4/ip_forward
80 iptables -t nat -A POSTROUTING -o ${netdev} -j MASQUERADE
81 [ "$dhcp" != 'no' ] && dhcp_start
86 [ "$dhcp" != 'no' ] && dhcp_stop
87 iptables -t nat -D POSTROUTING -o ${netdev} -j MASQUERADE
92 echo '============================================================'
98 echo '============================================================'
116 echo "Unknown command: $command" >&2
117 echo 'Valid commands are: start, stop, status' >&2