#!/bin/sh #---------------------------------------------------------------------------- # /var/install/config.d/base-net.sh - network sub script # Copyright (c) 2001-2017 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- PATH=/bin:/usr/bin:/sbin:/usr/sbin # include base-config . /etc/config.d/base #---------------------------------------------------------------------------- # create loopback #---------------------------------------------------------------------------- cat </etc/network/interfaces # Network config file auto lo iface lo inet loopback EOF #echo "loopback 127.0.0.0" > /etc/networks rm -f /etc/networks #---------------------------------------------------------------------------- # add interface template (openvz venet...) #---------------------------------------------------------------------------- [ -f /etc/network/interfaces.iface ] && cat /etc/network/interfaces.iface >> /etc/network/interfaces #---------------------------------------------------------------------------- # add network interface list #---------------------------------------------------------------------------- for idx in $(seq "0$IP_NET_N") do interface_nr=$(/usr/bin/expr $idx - 1) eval name='$IP_NET_'$idx'_NAME' [ -z "$name" ] && name="eth$interface_nr" eval active4='$IP_NET_'$idx'_IPV4_ACTIVE' eval static4='$IP_NET_'$idx'_IPV4_STATIC_IP' eval active6='$IP_NET_'$idx'_IPV6_ACTIVE' eval static6='$IP_NET_'$idx'_IPV6_STATIC_IP' if [ "$active4" = "yes" -o "$active6" = "yes" ] ; then echo "auto $name" >>/etc/network/interfaces fi # IPv4 ------------------------------------------------------------------ # use dhcp or static address if [ "$active4" = "yes" -a "$static4" = "no" ] ; then cat <<-EOF >>/etc/network/interfaces iface $name inet dhcp EOF elif [ "$active4" = "yes" ] ; then static_ip_use=true eval ipaddr='$IP_NET_'$idx'_IPV4_IPADDR' eval netmask='$IP_NET_'$idx'_IPV4_NETMASK' eval gateway='$IP_NET_'$idx'_IPV4_GATEWAY' eval point2p='$IP_NET_'$idx'_IPV4_POINTOPOINT' if [ -n "$ipaddr" -a "$ipaddr" != 0.0.0.0 ] then # network=$(/var/install/bin/netcalc network $ipaddr $netmask) # echo "localnet $network" >> /etc/networks cat <<-EOF >>/etc/network/interfaces iface $name inet static address $ipaddr netmask $netmask EOF { if [ -n "$gateway" ] ; then echo " gateway $gateway" [ "$point2p" = "yes" ] && echo " pointopoint $gateway" fi echo " hostname $HOSTNAME" echo "" } >>/etc/network/interfaces fi fi # IPv6 ------------------------------------------------------------------ # use dhcp or static address if [ "$active6" = "yes" -a "$static6" = "no" ] ; then cat <<-EOF >>/etc/network/interfaces iface $name inet6 dhcp EOF elif [ "$active6" = "yes" ] ; then static_ip_use=true eval ipaddr='$IP_NET_'$idx'_IPV6_IPADDR' eval netmask='$IP_NET_'$idx'_IPV6_NETMASKBITS' eval gateway='$IP_NET_'$idx'_IPV6_GATEWAY' eval point2p='$IP_NET_'$idx'_IPV6_POINTOPOINT' if [ -n "$ipaddr" -a "$ipaddr" != :: ] ; then # network=$(/var/install/bin/netcalc network $ipaddr $netmask) # echo "localnet $network" >> /etc/networks cat <<-EOF >>/etc/network/interfaces iface $name inet6 static address $ipaddr netmask $netmask EOF { if [ -n "$gateway" ] ; then echo " gateway $gateway" [ "$point2p" = "yes" ] && echo " pointopoint $gateway" fi echo " hostname $HOSTNAME" echo "" } >>/etc/network/interfaces fi fi done #---------------------------------------------------------------------------- # write resolv.config #---------------------------------------------------------------------------- if ${static_ip_use:-false} && [ -n "$DNS_SERVER$DOMAIN_NAME" ] then /etc/init.d/dhcpcd stop >/dev/null 2>&1 { [ -n "$DOMAIN_NAME" ] && echo "search $DOMAIN_NAME" # include first internal BIND9 or other DNS server [ -f /etc/resolv.conf.internal ] && echo "nameserver 127.0.0.1" for dns_server in $DNS_SERVER do echo "nameserver $dns_server" done } >/etc/resolv.conf fi #---------------------------------------------------------------------------- # write hostname config file #---------------------------------------------------------------------------- hostname $HOSTNAME echo $HOSTNAME >/etc/hostname [ "$IP_NET_1_IPV4_ACTIVE" == "yes" -a "$IP_NET_1_IPV4_STATIC_IP" = no ] && IP_NET_1_IPV4_IPADDR="127.0.1.1" cat </etc/hosts 127.0.0.1 localhost $IP_NET_1_IPV4_IPADDR $HOSTNAME.$DOMAIN_NAME $HOSTNAME # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts EOF #---------------------------------------------------------------------------- # write config for modules treatment #---------------------------------------------------------------------------- if [ -n "$MODULE_N" -a 0$MODULE_N -gt 0 ] then MODPROBE_FILE_EIS='/etc/modprobe.d/modules-eis.conf' rm -f $MODPROBE_FILE_EIS idx='1' while [ $idx -le $MODULE_N ] do eval mod='$MODULE_'$idx eval act='$MODULE_'$idx'_ACTION' eval strg='$MODULE_'$idx'_STRING' case $act in option) grep -qs "^options $mod $strg" $MODPROBE_FILE_EIS >/dev/null || echo "options $mod $strg" >>$MODPROBE_FILE_EIS ;; alias) grep -qs "^alias $strg $mod" $MODPROBE_FILE_EIS >/dev/null || echo "alias $strg $mod" >>$MODPROBE_FILE_EIS ;; blacklist) grep -qs "^blacklist $mod" $MODPROBE_FILE_EIS >/dev/null || echo "blacklist $mod" >>$MODPROBE_FILE_EIS ;; forcedstart) grep -qs "^$mod" /etc/modules >/dev/null || echo "$mod" >> /etc/modules ;; esac idx=$((idx+1)) done fi #---------------------------------------------------------------------------- # restart network #---------------------------------------------------------------------------- rc-update -q add networking boot if /var/install/bin/ask.cui "Should the network be re-initialized immediately?" then /etc/init.d/networking restart fi exit 0