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
Vs Code Ssh Remote Connection Issues
How to Generate a Static HTML File from a Swagger Documentation
Adjust Audio Volume Level with Cli Omxplayer - Raspberry Pi
Docker Run Hello-World Still Fails, Permission Denied
How to Specify Which Version of Perl to Use on Centos
Transpose Rows into Column in Unix
Tar Error: Unexpected Eof in Archive
Unix Bash Shell Programming If Directory Exists
Gdb Complains No Source Available
How to Convert Fixed Size Dimension to Unlimited in a Netcdf File
Copy Lines Containing Word from One File to Another File in Linux
How to Search for a Particular String from a .Gz File
Detecting The Output Stream Type of a Shell Script
Linux Kernel: Kernel Version String Appended with Either ''+" or "-Dirty"
Trouble with Vagrant - "404 - Not Found"
Crystalspace VS. Irrlicht VS. .....