我制作了2个webapps(我正在学习Web开发基础知识)。一个使用ruby-on-rails而另一个使用apache2。
我的笔记本电脑的本地IP为192.168.122.1
。
以下2个网址正在我的机器上运行:
1)ROR webapp - > http://192.168.122.1:3000
2)Apache2应用程序 - > http://192.168.122.1
但是,当我在局域网上的另一台设备/机器上键入相同的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中的一个错误,要么就是打开我不明白的端口。我尝试打开必要的端口80& 3000使用ufw但没有得到预期的结果。
我尝试通过键入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
的ifconfig:
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