Change netmask (but not ip) of network interface

ifconfignetmask

The ifconfig command can change both the ip address and netmask of a network interface:

ifconfig eth0 10.10.10.10 netmask 255.255.255.0

Is it possible to change the netmask of the network interface eth0 without knowing (and changing) it's ip address?

I've tried

ifconfig eth0 netmask 255.255.255.0

but I get the error

ifconfig: ioctl (SIOCAIFADDR): Invalid argument

Best Answer

Just specify the same IP address as currently configured with the new subnet mask to the ifconfig command.

ifconfig eth0 `/sbin/ifconfig eth0 | grep "inet addr" | tr -s " " | cut -f 3 -d " " | cut -f 2 -d ":"` netmask 255.255.255.0

(That makes me feel dirty...)

Edit:

Having said that, on an old-as-heck Fedora Core 2 box (the oldest box I could find on short notice) I am seeing ifconfig working fine to set the netmask w/o setting the IP. What version of net-tools are you looking at?