我在从浏览器访问默认反应页面时遇到问题。React应用程序在虚拟机上启动,虚拟机通过桥接网络连接到主机操作系统。
VM上的网络设置(CentOS 7(
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:ef:79:7b brd ff:ff:ff:ff:ff:ff
inet 192.168.2.18/24 brd 192.168.2.255 scope global noprefixroute dynamic ens33
valid_lft 19371sec preferred_lft 19371sec
inet6 fe80::da52:a805:4b32:ca69/64 scope link noprefixroute
valid_lft forever preferred_lft forever
主机操作系统(Windows 10(上的网络设置
Description. . . . . . . . . . . . . : Intel(R) Dual Band Wireless-AC 7265
MAC Address. . . . . . . . . : 7C-B0-C2-DF-7F-F5
DHCP enabled. . . . . . . . . . . : Yes
IPv4-address. . . . . . . . . . . . : 192.168.2.12(Primary)
Network Mask. . . . . . . . . . : 255.255.255.0
Default-gateway. . . . . . . . . : 192.168.2.1
DHCP-server. . . . . . . . . . . : 192.168.2.1
DNS-server. . . . . . . . . . . : 192.168.2.1
NetBios TCP/IP. . . . . . . . : Enabled
我可以从主机操作系统ping VM地址,没有问题(俄语字母,对不起(
C:Usersvud>ping 192.168.2.18
Обмен пакетами с 192.168.2.18 по с 32 байтами данных:
Ответ от 192.168.2.18: число байт=32 время<1мс TTL=64
Ответ от 192.168.2.18: число байт=32 время<1мс TTL=64
Ответ от 192.168.2.18: число байт=32 время<1мс TTL=64
所以我在VM上创建了一个测试前端项目:
[vud@centos~] create-app-react frontend
我从前端目录启动命令:
[vud@centos frontend]$ npm start
这告诉我服务器启动成功:
Compiled successfully!
You can now view frontend in the browser.
Local: http://localhost:3000
On Your Network: http://192.168.2.18:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
但我无法从Windows 10的浏览器访问它,导致连接超时
不过,这很有趣,因为我可以从VM:中卷曲页面内容
卷曲输出
因此,我还用tcpdump检查了端口3000上的流量,同时尝试从主机OS:通过浏览器访问react页面
[vud@centos frontend]$ sudo tcpdump -i ens33 host 192.168.2.12 and port 3000
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
21:36:09.886531 IP 192.168.2.12.56517 > centos.hbci: Flags [S], seq 2766461791, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
21:36:10.137042 IP 192.168.2.12.56518 > centos.hbci: Flags [S], seq 4251361662, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
21:36:12.886743 IP 192.168.2.12.56517 > centos.hbci: Flags [S], seq 2766461791, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
21:36:13.137883 IP 192.168.2.12.56518 > centos.hbci: Flags [S], seq 4251361662, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
21:36:18.887182 IP 192.168.2.12.56517 > centos.hbci: Flags [S], seq 2766461791, win 8192, options [mss 1460,nop,nop,sackOK], length 0
21:36:19.138951 IP 192.168.2.12.56518 > centos.hbci: Flags [S], seq 4251361662, win 8192, options [mss 1460,nop,nop,sackOK], length 0
SELINUX被禁用,btw
[vud@centos frontend]$ cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
由于某些原因,VM主机不接受连接。有没有一种方法可以导航嵌入式Web服务器的日志?我使用这个应用程序来学习docker,所以我对react/js/npm完全不熟悉。
附言:我访问过类似的话题,但他们并没有真正给我答案。
好的,禁用firewalld解决了问题
systemctl stop firewalld