* 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 }: lib.flip map interfacesNumbered ({ first, second }:
{ name = "eth${toString second}"; { name = "eth${toString second}";
ipAddress = "192.168.${toString first}.${toString m.second}"; ipAddress = "192.168.${toString first}.${toString m.second}";
subnetMask = "255.255.255.0";
} }
); );
in in

View File

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