First things first, do not use ifconfig
and route
. These commands are generally regarded as obsolete today; they were written too long ago when Linux had a very different network stack, and have been patched ever since. The very idea of interface aliases (e.g. ethX:YY) in order to have multiple addresses is obsolete today, they still exist mostly to please ifconfig itself. Today, the ip
command should satisfy all your needs.
Now, understand your original situation: Your eth0 interface originally had two active scopes: /24 and /27. 172.16.45.3 was the primary address for the /24 scope, while
172.16.45.21 was the primary address for the /27 scope (because it is listed first). When you issued the ifconfig command to change the prefix of the first address, it deleted it and reinserted it as a secondary address in the /27 scope. So now you should have something like this:
inet 172.16.45.21/27 brd 172.16.45.31 primary eth0:11
inet 172.16.45.22/27 brd 172.16.45.31 secondary eth0:12
inet 172.16.45.3/27 brd 172.16.45.31 secondary eth0
It doesn't matter that eth0 should be primary, or that it looks like it should be primary (another reason not to use ifconfig). It was inserted latter in the /27 scope, so it is a secondary address. This also means that outbound packets will be addressed 172.16.45.21, and that if you bring eth0:11 down using ifconfig, all your addresses will be taken down together. This is how it works.
The only way to fix this is to remove all addresses from the interface and reinsert them in the correct order. Then, the first address added (in the /27 scope) will be the primary address in that scope, and further addresses will all be secondaries.
The addressing was already broken from the beginning, there wasn't much you could do in this situation. Your best solution is to just restart the network service.
One possible workaround is to change the source routing address. This will have almost the same effect of changing the primary address. In your case:
ip route change 172.16.45.0/27 dev eth0 src 172.16.45.3
In this case, packets going to 172.16.45.0/27 will have the source address set to 172.16.45.3. You will need another command if you also want to change the source of packets passing through the gateway.
224.0.0.1 is disabled by default on linux 2.6+ hosts. From http://kerneltrap.org/node/16225
echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
I was able to reproduce this with my debian desktop at home:
From my macbook:
$ ping 224.0.0.1
PING 224.0.0.1 (224.0.0.1): 56 data bytes
64 bytes from 10.4.1.84: icmp_seq=0 ttl=64 time=0.227 ms
64 bytes from 10.4.1.8: icmp_seq=0 ttl=64 time=6.676 ms
On my debian box:
# echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
Then again on the macbook:
$ ping 224.0.0.1
PING 224.0.0.1 (224.0.0.1): 56 data bytes
64 bytes from 10.4.1.84: icmp_seq=0 ttl=64 time=0.301 ms
64 bytes from 10.4.1.12: icmp_seq=0 ttl=64 time=1.467 ms # my debian box
64 bytes from 10.4.1.8: icmp_seq=0 ttl=64 time=1.924 ms
Best Answer
Just specify the same IP address as currently configured with the new subnet mask to the
ifconfig
command.(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?