我读了很多页,尝试了很多东西,但被困在这里。
我有一个新安装的 Ubuntu 20.04 服务器。在它上面我运行了一个 Django 测试服务器(只是为了尝试一下)。它正在运行并侦听端口 8000。
我理解了:
$ sudo netstat -tulpen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 112 62240 47748/postgres
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1000 65495 48618/python
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 101 23068 755/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 27689 850/sshd: /usr/sbin
tcp6 0 0 :::5432 :::* LISTEN 112 62241 47748/postgres
tcp6 0 0 :::22 :::* LISTEN 0 27691 850/sshd: /usr/sbin
udp 0 0 127.0.0.53:53 0.0.0.0:* 101 23067 755/systemd-resolve
udp 0 0 192.168.0.15:68 0.0.0.0:* 100 23071 753/systemd-network
udp6 0 0 fe80::224:e8ff:fe22:546 :::* 100 23086 753/systemd-network
它的反应很好。我可以在服务器上做:
wget localhost:8000
我得到了回应。
所以现在我搬到我局域网上的台式机上。我尝试 wget:
$ wget server.lan:8000
--2020-10-11 11:42:18-- http://server.lan:8000/
Resolving server.lan (server.lan)... 192.168.0.15
Connecting to server.lan (server.lan)|192.168.0.15|:8000... failed: Connection refused.
果然:
$ nmap server.lan
Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-11 22:43 AEDT
Nmap scan report for server.lan (192.168.0.15)
Host is up (0.00025s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
5432/tcp open postgresql
Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
$ nmap serverlan -p 8000
Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-11 22:44 AEDT
Nmap scan report for server.lan (192.168.0.15)
Host is up (0.00068s latency).
PORT STATE SERVICE
8000/tcp closed http-alt
Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds
好的,服务器上的标准检查:
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:8000
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
因为我启用了端口 8000:
$ sudo iptables -A INPUT -p tcp --dport 8000 -j ACCEPT
遵循此处的说明:https ://www.e2enetworks.com/help/knowledge-base/how-to-open-ports-on-iptables-in-a-linux-server/
和:
$ sudo ufw status verbose
Status: inactive
然而从桌面上的lan 端口8000 是关闭的!
我应该注意端口 22 是打开的(就像我使用 ssh 登录到服务器一样,我也可以在端口 5432 上看到数据库并使用桌面上的 pgadmin4 管理它就好了,所以端口 22 和 5432 是打开,但我看不到iptables -L
它们是打开的。
Ubuntu 20.04 的神奇之处在于我在这里读过的许多页面都没有。
我什至可以很好地ping它:
$ ping arachne.lan
PING arachne.lan (192.168.0.15) 56(84) bytes of data.
64 bytes from 192.168.0.15 (192.168.0.15): icmp_seq=1 ttl=64 time=0.269 ms
64 bytes from 192.168.0.15 (192.168.0.15): icmp_seq=2 ttl=64 time=0.267 ms
64 bytes from 192.168.0.15 (192.168.0.15): icmp_seq=3 ttl=64 time=0.530 ms
64 bytes from 192.168.0.15 (192.168.0.15): icmp_seq=4 ttl=64 time=0.284 ms
64 bytes from 192.168.0.15 (192.168.0.15): icmp_seq=5 ttl=64 time=0.280 ms
64 bytes from 192.168.0.15 (192.168.0.15): icmp_seq=6 ttl=64 time=0.280 ms
所以因为我喜欢它并使用我安装cockpit
它并运行端口 9090。它从桌面安装和工作。
现在:
$ netstat -tulpen
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 112 62240 -
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1000 65495 48618/python
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 101 23068 -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 27689 -
tcp6 0 0 :::5432 :::* LISTEN 112 62241 -
tcp6 0 0 :::9090 :::* LISTEN 0 71091 -
tcp6 0 0 :::22 :::* LISTEN 0 27691 -
udp 0 0 127.0.0.53:53 0.0.0.0:* 101 23067 -
udp 0 0 192.168.0.15:68 0.0.0.0:* 100 23071 -
udp6 0 0 fe80::224:e8ff:fe22:546 :::* 100 23086 -
但 iptables 无所谓:
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:8000
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
但是台式机上的 nmap 可以看到它:
$ nmap server.lan
Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-11 22:55 AEDT
Nmap scan report for server.lan (192.168.0.15)
Host is up (0.00024s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
5432/tcp open postgresql
9090/tcp open zeus-admin
Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
所以 cockpit 和 postgresql 和 ssh 在安装时都以某种方式管理告诉 Ubuntu 20.04 打开一个端口。
因此,通过内省的 nmap 查看服务器:
$ nmap localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-11 11:58 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00021s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
5432/tcp open postgresql
8000/tcp open http-alt
9090/tcp open zeus-admin
Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
端口 8000 看起来是打开的。
桌面和服务器之间没有防火墙,只有一个标准的 LAN 交换机。
怎么样,cockpit、postgresql 和 ssh 都可以实现某些目标,但很难弄清楚他们实现了什么以及如何实现它?iptables
他们似乎不使用它。也不是ufw
。我错过了什么魔法?如何打开 8000 端口?