Ich bin auf macOS Sierra umgestiegen und kann die Portweiterleitung für localhost (http und https) mit der Loopback-Schnittstelle lo0 nicht zum Laufen bringen. Ich verwende pf und befolge die vorhandenen Anweisungen für El Capitan, aber ohne Erfolg:
https://apple.stackexchange.com/a/230331/81267 , http://blog.brianjohn.com/forwarding-ports-in-os-x-el-capitan.html
Grundsätzlich richte ich ifconfig ein:
sudo ifconfig lo0 10.0.0.1 alias
Dann erstelle ich eine pf
Ankerdatei:/etc/pf.anchors/myorganization
rdr pass on lo0 inet proto tcp from any to 10.0.0.1 port = 80 -> 127.0.0.1 port 3000
rdr pass on lo0 inet proto tcp from any to 10.0.0.1 port = 443 -> 127.0.0.1 port 7000
Fügen Sie einen Verweis darauf in pf.conf hinzu (musste SIP deaktivieren und dann wieder aktivieren, um dies zu tun):
rdr-anchor "myorganization"
...
load anchor "myorganization" from "/etc/pf.anchors/myorganization"
Ich teste die Anker:
sudo pfctl -vnf /etc/pf.anchors/myorganization
und das Ergebnis sieht gut aus:
...
TRANSLATION RULES:
nat-anchor "com.apple/*" all
rdr-anchor "com.apple/*" all
rdr-anchor "myorganization" all
...
Ich habe sie aktiviert:
sudo pfctl -evf /etc/pf.conf
Ich habe localhost
meine /etc/hosts hinzugefügt
127.0.0.1 localhost
Aber wenn ich zu navigiere http://localhost
bekomme ich ERR_CONNECTION_REFUSED
. Wenn ich auf http://localhost:3000
die Seite navigiere, funktioniert es einwandfrei.
Update Ich habe die pf-Protokollierung aktiviert und es ohne den Alias 10.0.0.1 versucht:
rdr pass log (all) on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 3000
rdr pass log (all) on lo0 inet proto tcp from any to any port 443 -> 127.0.0.1 port 7000
Und wenn ich zum ersten Mal auf http://localhost drücke , sehe ich das Protokoll:
00:00:00.000000 rule 4294967295/8(ip-option): pass in on en0: (tos 0x0, ttl 1, id 59674, offset 0, flags [none], proto IGMP (2), length 32, options (RA))
192.168.0.106 > 224.0.1.60: igmp v2 report 224.0.1.60
00:00:00.204784 rule 4294967295/8(ip-option): pass in on en0: (tos 0xc0, ttl 1, id 0, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
192.168.0.3 > 224.0.0.252: igmp v2 report 224.0.0.252
00:00:00.093232 rule 4294967295/8(ip-option): pass out on en0: (tos 0x0, ttl 1, id 11047, offset 0, flags [none], proto IGMP (2), length 32, options (RA))
192.168.0.77 > 224.0.0.251: igmp v2 report 224.0.0.251
00:00:00.111608 rule 4294967295/8(ip-option): pass in on en0: (tos 0x0, ttl 1, id 60629, offset 0, flags [none], proto IGMP (2), length 32, options (RA))
192.168.0.106 > 239.255.255.250: igmp v2 report 239.255.255.250
00:00:00.102426 rule 4294967295/8(ip-option): pass in on en0: (tos 0xc0, ttl 1, id 0, offset 0, flags [DF], proto IGMP (2), length 32, options (RA))
192.168.0.3 > 224.0.0.251: igmp v2 report 224.0.0.251
00:00:00.000120 rule 4294967295/8(ip-option): pass in on en0: (tos 0xc0, ttl 1, id 0, offset 0, flags [DF], proto IGMP (2), length 48, options (RA))
192.168.0.3 > 224.0.0.22: igmp v3 report, 2 group record(s) [gaddr 224.0.0.251 is_ex, 0 source(s)] [gaddr 224.0.0.252 is_ex, 0 source(s)]
Nachfolgende Zugriffe auf localhost fügen den Protokollen nichts hinzu, und ich sehe, dass die Loopback-Schnittstelle lo0 in diesem Protokoll nicht angezeigt wird, sondern nur en0 (Ethernet). Daher bin ich nicht davon überzeugt, dass diese Protokollausgabe für das Problem relevant ist. Ich habe auch versucht, en0 und en1 zur /etc/pf.anchors/myorganization
Datei hinzuzufügen, aber die gleichen Ergebnisse.
Meine Antwort auf die Frage: Was ist die moderne Art, Port-Forwarding auf El Capitan zu machen? (Port 80 auf 8080 weiterleiten) ist weiterhin gültig.
Sie haben jedoch mehrere Reibungen / Fehlkonfigurationen in Ihrem Setup:
Eine Weiterleitung:
rdr pass on lo0 inet proto tcp from any to 10.0.0.1 port = 80 -> 127.0.0.1 port 3000
leitet nur eine Anfrage für 10.0.0.1:80 auf 127.0.0.1:3000 um.
Eine Anfrage für localhost:80 (was 127.0.0.1:80 und nicht 10.0.0.1:80 entspricht) wird nicht umgeleitet, da es keine entsprechende rdr ...
Zeile gibt und Sie einen Verbindungsfehler erhalten.
10.0.0.1 localhost
zu /etc/hosts wird Ihr Problem nicht retten, da localhost auf 127.0.0.1 fest codiert zu sein scheint.Damit Ihre Umleitung funktioniert, entladen Sie pf.conf mit sudo pfctl -d
. Überprüfen Sie dann Ihren Anker und pf.conf:
rdr pass log (all) on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 3000
rdr pass log (all) on lo0 inet proto tcp from any to any port 443 -> 127.0.0.1 port 7000
Und
...
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "myorganization"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
load anchor "myorganization" from "/etc/pf.anchors/myorganization"
Dann parse/check myorganization mit sudo pfctl -vnf /etc/pf.anchors/myorganization
und lade pf.conf mit sudo pfctl -evf /etc/pf.conf
.
In einigen seltenen Fällen müssen Sie möglicherweise eine zusätzliche Zeile hinzufügen :
::1 127.0.0.1
in Ihre /etc/hosts-Datei. Dies erscheint jedoch nicht logisch und trifft möglicherweise nur auf ältere Sierra-Versionen zu. Dies konnte ich nicht bestätigen.
klanomath
Daniel Flippance
klanomath
Daniel Flippance
Daniel Flippance