I'm wondering one thing. I'm playing with an EC2 instance and would like to use some local subnet in the 192.168.1.0/29 range. So I've setup aliases on eth0 as follow:
[root@server jvehent]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 12:25:8B:0a:B1:EB
inet addr:10.28.118.95 Bcast:10.28.118.255 Mask:255.255.254.0
[...]
eth0:1 Link encap:Ethernet HWaddr 12:25:8B:0a:B1:EB
inet addr:192.168.1.1 Bcast:192.168.1.7 Mask:255.255.255.248
[...]
eth0:2 Link encap:Ethernet HWaddr 12:25:8B:0a:B1:EB
inet addr:192.168.1.2 Bcast:192.168.1.7 Mask:255.255.255.248
[...]
eth0:3 Link encap:Ethernet HWaddr 12:25:8B:0a:B1:EB
inet addr:192.168.1.3 Bcast:192.168.1.7 Mask:255.255.255.248
[...]
eth0:4 Link encap:Ethernet HWaddr 12:25:8B:0a:B1:EB
inet addr:192.168.1.4 Bcast:192.168.1.7 Mask:255.255.255.248
[...]
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
Very well, so I get the following routing table
[root@server jvehent]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.248 U 0 0 0 eth0
10.28.118.0 0.0.0.0 255.255.254.0 U 0 0 0 eth0
0.0.0.0 10.28.118.1 0.0.0.0 UG 0 0 0 eth0
Now, If I want two services to talk to each other using the local aliases, I can set netcat as follow:
listening netcat:
nc -l 192.168.1.4 1664
connecting netcat:
nc -s 192.168.1.1 192.168.1.4 1664
And, from what I see, that traffic goes through the localhost interface. I'm checking with tcpdump -i lo and I see packets going through. Nothing on eth0.
My basic knowledge of the kernel tell me that since the kernel owns all the ip, it does all the operations internally and copy the packets from a socket to another without passing it to the NIC. correct ?
Is there a way to force the kernel to send those packets on the network ?
Yes, No. Yep the kernel short circuits it by passing it to the loopback interface. No you couldn't send them out to the network because the network wouldn't send them back. The NIC can send or receive a packet, it can't both send the packet and receive it back at the same time. (Perhaps a switch could be programmed to simulate this, but you're on an EC2 instance, and there is no switch in the first place; heck there's no NIC)