Answer the question
In order to leave comments, you need to log in
Why is the connection from localhost not working?
There was such problem:
There is an address: my_host.ru
Certain ports are proxied on virtual machines.
If you go to the url my_host.ru:8083 Welcome to socket.io.
If I write this code on a third-party server (for example, on my LAN)
function get_content($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
}
echo get_content('мой_хост.ru:8083');
Answer the question
In order to leave comments, you need to log in
Modeled on my server.
When requesting by the name of the current host, the request goes not to eth0, but to lo (thanks, tcpdump)
PREROUTING does not work for the loopback (thanks to serverfault.com
) example)
those.
iptables -t nat -I OUTPUT -p tcp -o lo --dport 8083 -j DNAT --to-destination 192.168.1.124:8083
hostname && printf "\n\n" && cat /etc/hosts && printf "\n\n" && iptables-save > /tmp/ipt && cat /tmp/ipt
127.0.0.1 localhost
my ip, provider, everything
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
# Generated by iptables-save v1.4.14 on Mon Apr 28 12:37: 08 2014
*filter
:INPUT ACCEPT [365791:134637737]
:FORWARD ACCEPT [327624:179575394]
:OUTPUT ACCEPT [341288:160694049]
COMMIT
# Completed on Mon Apr 28 12:37:08 2014
# Generated by v1tables.4-s14 on Mon Apr 28 12:37:08 2014
*mangle
: PREROUTING ACCEPT [693 617: 314 244 891]
: the ACCEPT the INPUT [365925: 134 653 211]
: the FORWARD the ACCEPT [327 624: 179 575 394]
: the ACCEPT the OUTPUT [341417: 160 713 451]
: the POSTROUTING the ACCEPT [669 041: 340 288 845] a
COMMIT
# the Completed on Mon Apr 28, 12:37 :08 2014
# Generated by iptables-save v1.4.14 on Mon Apr 28 12:37:08 2014
*nat
:PREROUTING ACCEPT [1969:131473]
:POSTROUTING ACCEPT [851:49148]
:OUTPUT ACCEPT [721:43393]
-A PREROUTING -i eth0 -p tcp -m tcp --dport 8081 -j DNAT --to-destination 192.168.1.121:8081
-A PREROUTING -i eth0 -p tcp -m tcp --dport 8082 -j DNAT --to- destination 192.168.1.121:8082
-A PREROUTING -i eth0 -p tcp -m tcp --dport 8083 -j DNAT --to-destination 192.168.1.124:8083
-A PREROUTING -i eth0 -p tcp -m tcp --dport 8084 -j DNAT -- to-destination 192.168.1.124:8084
-A PREROUTING -i eth0 -p tcp -m tcp --dport 8089 -j DNAT --to-destination 192.168.1.122:8089
-A PREROUTING -i eth0 -p tcp -m tcp - -dport 8321 -j DNAT --to-destination 192.168.2.121:8321
-A PREROUTING -i eth0 -p tcp -m tcp --dport 8322 -j DNAT --to-destination 192.168.2.122:8322
-A PREROUTING -i eth0 -p tcp -m tcp --dport 8323 -j DNAT --to-destination 192.168.2.123:8323
-A PREROUTING -i eth0 -p tcp -m tcp --dport 8324 -j DNAT --to-destination 192.168. 2.124:8324
-A POSTROUTING -o eth0 -j MASQUERADE
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Mon Apr 28 12:37:08 2014
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question