* Use "ip" instead of "ifconfig" for setting up network interfaces,

since the latter is rather deprecated and has been unmaintained
  since 2001.  Note that "ip" doesn't know about classful addressing,
  so you can no longer get away with not specifying the subnet mask
  for explicitly configured interfaces.  So if you had

    networking.interfaces =
      [ { name = "eth0"; ipAddress = "192.168.1.1"; } ];

  this should be changed to

    networking.interfaces =
      [ { name = "eth0";
          ipAddress = "192.168.1.1";
          subnetMask = "255.255.255.0";
        }
     ];

  otherwise you end up with a subnet mask of 255.255.255.255.

svn path=/nixos/trunk/; revision=26279
This commit is contained in:
Eelco Dolstra 2011-03-11 14:50:11 +00:00
parent d6090b9d1e
commit 8ce36ffb3a
2 changed files with 16 additions and 32 deletions

View File

@ -51,6 +51,7 @@ rec {
lib.flip map interfacesNumbered ({ first, second }:
{ name = "eth${toString second}";
ipAddress = "192.168.${toString first}.${toString m.second}";
subnetMask = "255.255.255.0";
}
);
in

View File

@ -4,12 +4,8 @@ with pkgs.lib;
let
inherit (pkgs) nettools;
cfg = config.networking;
ifconfig = "${nettools}/sbin/ifconfig";
in
{
@ -166,33 +162,28 @@ in
preStart =
''
${pkgs.lib.concatMapStrings (i:
if i.macAddress != "" then
${flip concatMapStrings cfg.interfaces (i:
optionalString (i.macAddress != "")
''
echo "Configuring interface ${i.name}..."
${ifconfig} "${i.name}" down || true
${ifconfig} "${i.name}" hw ether "${i.macAddress}" || true
''
else "") cfg.interfaces
echo "Setting MAC address of ${i.name} to ${i.macAddress}..."
ip link set "${i.name}" address "${i.macAddress}" || true
'')
}
for i in $(cd /sys/class/net && ls -d *); do
echo "Bringing up network device $i..."
${ifconfig} $i up || true
ip link set "$i" up || true
done
# Configure the manually specified interfaces.
${pkgs.lib.concatMapStrings (i:
if i.ipAddress != "" then
${flip concatMapStrings cfg.interfaces (i:
optionalString (i.ipAddress != "")
''
echo "Configuring interface ${i.name}..."
extraFlags=
if test -n "${i.subnetMask}"; then
extraFlags="$extraFlags netmask ${i.subnetMask}"
fi
${ifconfig} "${i.name}" "${i.ipAddress}" $extraFlags || true
''
else "") cfg.interfaces}
ip addr add "${i.ipAddress}""${optionalString (i.subnetMask != "") ("/" + i.subnetMask)}" \
dev "${i.name}" || true
'')
}
# Set the nameservers.
if test -n "${toString cfg.nameservers}"; then
@ -206,9 +197,9 @@ in
fi
# Set the default gateway.
if test -n "${cfg.defaultGateway}"; then
${nettools}/sbin/route add default gw "${cfg.defaultGateway}" || true
fi
${optionalString (cfg.defaultGateway != "") ''
ip route add default via "${cfg.defaultGateway}" || true
''}
# Run any user-specified commands.
${pkgs.stdenv.shell} ${pkgs.writeText "local-net-cmds" cfg.localCommands} || true
@ -218,14 +209,6 @@ in
initctl emit -n ip-up
''}
'';
postStop =
''
#for i in $(cd /sys/class/net && ls -d *); do
# echo "Taking down network device $i..."
# ${ifconfig} $i down || true
#done
'';
};
# Set the host name in the activation script. Don't clear it if