Hi Andrew. In order to add/change nics I also run:
Nic_Config () {
echo "Starting NIC Discovery and Configuration" > $MESSGFILE
# Find out, what nic configuration we have. This is needed for later on to fill the database
# correctly.
if [[ `ifconfig -s -a | awk '$1 != "Iface" && $1 != "lo" && $1 != "pan0" { print $1 }' | wc -l` > 1 ]]; then
Create_Wizard_Data-Double_Nic_Shell > ${mce_wizard_data_shell}
#Use these for the defaults if we cannot automatically determine which to use
#TODO: Error out and instruct the user to setup a working connection? Or ask them to manually choose?
extif="eth0"
intif="eth1"
if route -n | grep -q '^0.0.0.0'; then
#We have a default route, use it for finding external interface.
extif=`route -n | awk '$1 == "0.0.0.0" { print $8 }'`
#Use the first available interface as the internal interface.
for if in `ifconfig -s -a | awk '$1 != "Iface" && $1 != "lo" && $1 != "pan0" { print $1 }'`; do
if [ "$if" != "$extif" ]
then
intif=$if
break
fi
done
fi
echo "Using $extif for external interface" > $MESSGFILE
sleep 2
echo "Using $intif for internal interface" > $MESSGFILE
sed --in-place -e "s,\({extif}\),$extif,g" ${mce_wizard_data_shell}
sed --in-place -e "s,\({intif}\),$intif,g" ${mce_wizard_data_shell}
else
extif=eth0
if route -n | grep -q '^0.0.0.0'
then
#We have a default route, use it for finding external interface.
extif=`route -n | awk '$1 == "0.0.0.0" { print $8 }'`
fi
Create_Wizard_Data-Single_Nic_Shell > ${mce_wizard_data_shell}
echo "Using $extif for single nic install" > $MESSGFILE
sed --in-place -e "s,\({extif}\),$extif,g" ${mce_wizard_data_shell}
# set c_netExtIP and friends , as this is used in Configure_Network_Options (i.e. before Network_Setup...)
extIP=$(ip addr | grep "$extif" | grep -m 1 'inet ' | awk '{print $2}' | cut -d/ -f1)
sed --in-place -e "s,\({extip}\),$extIP,g" ${mce_wizard_data_shell}
# Set use external DHCP and run own dhcp based on extifs current setting
ExtUsesDhcp=$(grep "iface $extif " /etc/network/interfaces | grep -cF 'dhcp')
if [[ $ExtUsesDhcp == 0 ]]
then
# Not dhcp defined in config file, test if dhclient got us an IP
# /var/run/dhcp3 for newer than 810, /var/run in 810
if [[ (`ls /var/lib/dhcp3/dhclient-*-$extif.lease && [[ $? == 0 ]]` || -e /var/run/dhclient-$extif.pid) && `pgrep -c dhclient` == 1 ]]
then
ExtUsesDhcp=1
fi
fi
RunDHCP=0
if [[ $ExtUsesDhcp == 0 ]]
then
echo "$extif does not use DHCP, setting ExtUseDhcp=0 and RunDHCPServer=1 and detecting current network settings" > $MESSGFILE
RunDHCP=1
ExtGateway=$(grep -A 10 "^iface $extif" /etc/network/interfaces | grep '^\s*gateway' -m 1 | grep -o '[0-9.]*')
ExtMask=$(grep -A 10 "^iface $extif" /etc/network/interfaces | grep '^\s*netmask' -m 1 | grep -o '[0-9.]*')
ExtDNS=$(grep 'nameserver' /etc/resolv.conf | grep -o '[0-9.]*' -m 1)
fi
sed --in-place -e "s,\({extMask}\),$ExtMask,g" ${mce_wizard_data_shell}
sed --in-place -e "s,\({extGW}\),$ExtGateway,g" ${mce_wizard_data_shell}
sed --in-place -e "s,\({extDNS}\),$ExtDNS,g" ${mce_wizard_data_shell}
sed --in-place -e "s,\({extUseDhcp}\),$ExtUsesDhcp,g" ${mce_wizard_data_shell}
sed --in-place -e "s,\({runDhcp}\),$RunDHCP,g" ${mce_wizard_data_shell}
fi
if [[ ! -r ${mce_wizard_data_shell} ]]; then
echo "`date` - Wizard Information is corrupted or missing." > $MESSGFILE
exit 1
fi
. ${mce_wizard_data_shell}
VerifyExitCode "MCE Wizard Data"
Core_PK_Device="0"
#Setup the network interfaces
echo > /etc/network/interfaces
echo "auto lo" >> /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces
echo >> /etc/network/interfaces
echo "auto $c_netExtName" >> /etc/network/interfaces
if [[ $c_netExtUseDhcp == "1" ]] ;then
echo " iface $c_netExtName inet dhcp" >> /etc/network/interfaces
else
if [[ "$c_netExtIP" != "" ]] && [[ "$c_netExtName" != "" ]] &&
[[ "$c_netExtMask" != "" ]] && [[ "$c_netExtGateway" != "" ]] ;then
echo "" >> /etc/network/interfaces
echo " iface $c_netExtName inet static" >> /etc/network/interfaces
echo " address $c_netExtIP" >> /etc/network/interfaces
echo " netmask $c_netExtMask" >> /etc/network/interfaces
echo " gateway $c_netExtGateway" >> /etc/network/interfaces
fi
fi
echo "" >> /etc/network/interfaces
echo "auto $c_netIntName" >> /etc/network/interfaces
echo " iface $c_netIntName inet static" >> /etc/network/interfaces
echo " address $c_netIntIPN" >> /etc/network/interfaces
echo " netmask 255.255.255.0" >> /etc/network/interfaces
}
Configure_Network_Options () {
# Updating hosts file and the Device_Data for the core with the internal and external network
# addresses - uses Initial_DHCP_Config.sh from the pluto-install-scripts package.
echo "Configuring your internal network" > $MESSGFILE
#Source the SQL Ops file
## Setup /etc/hosts
cat <<EOL > /etc/hosts
127.0.0.1 localhost.localdomain localhost
$c_netExtIP dcerouter $(/bin/hostname)
EOL
error=false
Network=""
Digits_Count=0
for Digits in $(echo "$c_netIntIPN" | tr '.' ' ') ;do
[[ "$Digits" == *[^0-9]* ]] && error=true
[[ $Digits -lt 0 || $Digits -gt 255 ]] && error=true
if [[ "$Network" == "" ]] ;then
Network="$Digits"
else
Network="${Network}.${Digits}"
fi
Digits_Count=$(( $Digits_Count + 1 ))
done
[[ $Digits_Count -lt 1 || $Digits_Count -gt 3 ]] && error=true
if [[ "$error" == "true" ]] ;then
Network="192.168.80"
Digits_Count="3"
fi
IntIP="$Network"
IntNetmask=""
for i in `seq 1 $Digits_Count` ;do
if [[ "$IntNetmask" == "" ]] ;then
IntNetmask="255"
else
IntNetmask="${IntNetmask}.255"
fi
done
for i in `seq $Digits_Count 3` ;do
if [[ $i == "3" ]] ;then
IntIP="${IntIP}.1"
else
IntIP="${IntIP}.0"
fi
IntNetmask="${IntNetmask}.0"
done
if [[ "$c_netIntName" == "" ]] ;then
IntIf="$c_netExtName:0"
else
IntIf="$c_netIntName"
fi
if [[ "$c_singleNIC" == "1" ]] ;then
#Disable firewalls on single NIC operation, refs #396
echo "We are in single NIC mode -> internal firewalls disabled"
echo "DisableFirewall=1" >>/etc/pluto.conf
echo "DisableIPv6Firewall=1" >>/etc/pluto.conf
fi
if [[ "$c_netExtUseDhcp" == "0" ]] ;then
NETsetting="$c_netExtName,$c_netExtIP,$c_netExtMask,$c_netExtGateway,$c_netExtDNS1|$IntIf,$IntIP,$IntNetmask"
else
NETsetting="$c_netExtName,dhcp|$IntIf,$IntIP,$IntNetmask"
fi
DHCPsetting=$(/usr/pluto/install/Initial_DHCP_Config.sh "$Network" "$Digits_Count")
Q="REPLACE INTO Device_DeviceData(FK_Device,FK_DeviceData,IK_DeviceData) VALUES('$Core_PK_Device',32,'$NETsetting')"
RunSQL "$Q"
if [[ "$c_runDhcpServer" == "1" ]]; then
Q="REPLACE INTO Device_DeviceData(FK_Device, FK_DeviceData, IK_DeviceData)
VALUES($Core_PK_Device, 28, '$DHCPsetting')"
RunSQL "$Q"
fi
# create empty IPv6 tunnel settings field
Q="REPLACE INTO Device_DeviceData(FK_Device,FK_DeviceData,IK_DeviceData) VALUES('$Core_PK_Device',292,'')"
RunSQL "$Q"
}
SetupNetworking () {
rm -f /etc/X11/xorg.conf
rm -f /etc/network/interfaces
## Reconfigure networking
/usr/pluto/bin/Network_Setup.sh
/usr/pluto/bin/ConfirmInstallation.sh
/usr/pluto/bin/Timezone_Detect.sh
}
Nic_Config
Configure_Network_Options
SetupNetworking
In a script to set values up in the DB appropriately after changing udev net.rules. I am sure that you have a less complicated method of doing this... just thought I would throw it out there.