Linux: Disable Using Loopback and Send Data via Wire Between 2 Eth Cards of One Comp

Does a connection to localhost go out onto the network?

No packets will hit the network. Unplug your network cable and try it!

using netcat for external loop-back test between two ports

Internal routing is preferred because in the default routing behaviour you have all the internal routes marked as scope link in the local table. Check this out with:

ip rule show
ip route show table local

If your kernel supports multiple routing tables you can simply alter the local table to achieve your goal. You don't need iptables.

Let's say 192.168.1.1 is your target ip address and eth0 is the interface where you want to send your packets out to the wire.

ip route add 192.168.1.1/32 dev eth0 table local

Finding local IP addresses using Python's stdlib

import socket
socket.gethostbyname(socket.gethostname())

This won't work always (returns 127.0.0.1 on machines having the hostname in /etc/hosts as 127.0.0.1), a paliative would be what gimel shows, use socket.getfqdn() instead. Of course your machine needs a resolvable hostname.



Related Topics



Leave a reply



Submit