1

我制作了 2 个 webapps(我正在学习 web 开发基础知识)。一个使用 ruby​​-on-rails,另一个使用 apache2。

我的笔记本电脑的本地 IP 是192.168.122.1.

以下 2 个 url 在我的机器上运行:1) ROR webapp -> http://192.168.122.1:3000 2) Apache2 App ->http://192.168.122.1

但是,当我在 LAN 上的另一台设备/机器上键入相同的 URL 时,我得到 ERR_CONNECTION_REFUSED。

当我在终端中输入以下内容时:sudo nc -v 192.168.122.1 3000,我收到了消息Connection to 192.168.122.1 3000 port [tcp/*] succeeded!

我认为这不是 rails 或 apache2 的问题,而是 Ubuntu OS 中的错误,或者有一些关于打开端口的问题,我不明白。我尝试使用 ufw 打开必要的端口 80 和 3000,但没有得到预期的结果。我尝试通过键入完全禁用防火墙(当然不是一个好习惯)sudo ufw disable。但是,它没有任何效果。我仍然面临同样的问题。

我正在使用 Ubuntu 16.04。大约 4 年前,我在 Ubuntu 12.04 上开发了一个基本的 Web 应用程序,从来没有遇到过这样的问题。

iptables:

umangmathur@Acer-Aspire-V3-571:~$ sudo iptables -L
[sudo] password for umangmathur: 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3000
ACCEPT     udp  --  anywhere             anywhere             udp dpt:domain
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:domain
ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootps
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:bootps
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             192.168.122.0/24     ctstate RELATED,ESTABLISHED
ACCEPT     all  --  192.168.122.0/24     anywhere            
ACCEPT     all  --  anywhere             anywhere            
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootpc

如果配置:

umangmathur@Acer-Aspire-V3-571:~$ ifconfig
enp2s0f0  Link encap:Ethernet  HWaddr b8:88:e3:0b:04:c4  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:16 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:15396 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15396 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1646030 (1.6 MB)  TX bytes:1646030 (1.6 MB)

virbr0    Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlp3s0    Link encap:Ethernet  HWaddr 08:3e:8e:2a:10:81  
          inet addr:192.168.43.129  Bcast:192.168.43.255  Mask:255.255.255.0
          inet6 addr: fe80::99e9:db42:eceb:a526/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:544441 errors:0 dropped:0 overruns:0 frame:0
          TX packets:302249 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:710738799 (710.7 MB)  TX bytes:46367641 (46.3 MB)

监听端口列表(使用 netstat):

umangmathur@Acer-Aspire-V3-571:~$ sudo netstat -patune | grep LISTEN
[sudo] password for umangmathur: 
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      123        23438       1110/mysqld     
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      0          31251       2361/smbd       
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      0          26992       1508/dnsmasq    
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      0          27672       1406/dnsmasq    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          233420      1082/sshd       
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      0          23217       923/cupsd       
tcp        0      0 192.168.122.1:3000      0.0.0.0:*               LISTEN      1000       71774       4678/192.168.122.1:
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      0          31250       2361/smbd       
tcp6       0      0 :::139                  :::*                    LISTEN      0          31249       2361/smbd       
tcp6       0      0 :::80                   :::*                    LISTEN      0          28945       1861/apache2    
tcp6       0      0 :::22                   :::*                    LISTEN      0          233422      1082/sshd       
tcp6       0      0 ::1:631                 :::*                    LISTEN      0          23216       923/cupsd       
tcp6       0      0 :::445                  :::*                    LISTEN      0          31248       2361/smbd       
4

0 回答 0