Change netmask (but not ip) of network interface

Solution 1:

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?

Solution 2:

If you don't know what the IP is, just

ifconfig eth0

and it will be displayed. Then you can use that in your configuration command.