当我运行程序时,监听指定地址和端口的命令行,它完全正常:
/usr/bin/https_dns_proxy -t http://localhost:3128 -a 127.0.0.1 -p 5054
给我:
dig @127.0.0.1 -p 5054 www.amazon.com
; <<>> DiG 9.11.3-1ubuntu1-Ubuntu <<>> @127.0.0.1 -p 5054 www.amazon.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5356
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.amazon.com. IN A
;; ANSWER SECTION:
www.amazon.com. 162 IN CNAME www.cdn.amazon.com.
www.cdn.amazon.com. 46 IN CNAME www.amazon.com.edgekey.net.
www.amazon.com.edgekey.net. 105 IN CNAME e15316.ci.akamaiedge.net.
e15316.ci.akamaiedge.net. 6 IN A 104.117.47.132
;; Query time: 29 msec
;; SERVER: 127.0.0.1#5054(127.0.0.1)
;; WHEN: Mon Jun 11 13:52:15 EDT 2018
;; MSG SIZE rcvd: 158
但是,当我通过systemd运行程序时,它不起作用:
$ sudo systemctl status https-dns-proxy.service
● https-dns-proxy.service - Resolve DNS queries over HTTPS.
Loaded: loaded (/lib/systemd/system/https-dns-proxy.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Mon 2018-06-11 13:52:09 EDT; 1min 20s ago
Process: 8338 ExecStart=/usr/bin/https_dns_proxy ${DAEMON_ARGS} (code=killed, signal=TERM)
Main PID: 8338 (code=killed, signal=TERM)
$ sudo systemctl start https-dns-proxy.service
$ sudo systemctl status https-dns-proxy.service
● https-dns-proxy.service - Resolve DNS queries over HTTPS.
Loaded: loaded (/lib/systemd/system/https-dns-proxy.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-06-11 13:54:31 EDT; 2s ago
Main PID: 12635 (https_dns_proxy)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/https-dns-proxy.service
└─12635 /usr/bin/https_dns_proxy -t http://localhost:3128 -a 127.0.0.1 -p 5054
Jun 11 13:54:31 DEV-M-20T3W systemd[1]: Started Resolve DNS queries over HTTPS..
$ dig @127.0.0.1 -p 5054 www.amazon.com
; <<>> DiG 9.11.3-1ubuntu1-Ubuntu <<>> @127.0.0.1 -p 5054 www.amazon.com
; (1 server found)
;; global options: +cmd
;; connection timed out; no servers could be reached
为什么在使用systemd运行程序时应用程序没有侦听指定的端口?
单位档案:
[Unit]
Description=Resolve DNS queries over HTTPS.
After=network.target
[Service]
User=nobody
Group=nogroup
EnvironmentFile=-/etc/default/https-dns-proxy
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/https_dns_proxy ${DAEMON_ARGS}
[Install]
WantedBy=multi-user.target