In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Background
Two network cards are configured for the VirtualBox virtual machine (loaded with the Ubuntu16.04 system). The network mode is "Network address Translation (NAT)" and "host-only (Host-Only) adapter", in which the enp0s3 network card (NAT) is used for external network access, and the enp0s8 network card (Host-Only) is used for host access to the virtual machine. However, after the virtual machine is started, it cannot access the external network.
Positioning
The network profile is as follows:
# vi / etc/network/interface...# The primary network interfaceauto enp0s3iface enp0s3 inet dhcpauto enp0s8iface enp0s8 inet staticaddress 192.168.137.16netmask 255.255.255.0gateway 192.168.137.1
Eth0 uses dhcp,eth2 and static. The actual network of eth0 is as follows:
# ifconfig enp0s3: flags=4163 mtu 1500 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:fe55:2858 prefixlen 64 scopeid 0x20 ether 08 KB 2755 KB 58 txqueuelen 1000 (Ethernet) RX packets 6 bytes 1476 (1.4 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 33 bytes 3108 (3.1 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
The problem was discovered when the route was turned on.
# route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.137.1 0.0.0.0 UG 0 000 enp0s810.0.2.0 0.0.0.0 255.255.255.0 U 000 enp0s3192.168.137.0 0.0.0.0 255.255.255.0 U 000 enp0s8
The enp0s8 network card becomes the default route, which causes the network segments that cannot be matched by other routes to use the enp0s8 network card. In fact, the virtual network card that we configure to connect with the external network is enp0s3, so the environment will not be able to connect to the external network. We can try to delete the current default route manually.
# route del default# route add default gw 10.0.2.2 dev enp0s3# route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault gateway 0.0.0.0 UG 0 000 enp0s310.0.2.0 0.0.0.0 255.255.255.0 U 000 enp0s3192.168.137.0 0.0.0.0 255.255.255.0 U 000 enp0s8
The route is set up successfully, and OS can also access the public network. But this only modifies the routing settings this time, and the OS will expire after restarting, so we need to persist the configuration.
Persistent routing configuration
We set route persistence in the network configuration file / etc/network/interfaces. Add the corresponding routing addition and deletion code after the Nic is started, similar to the route command, except that you can add up at the beginning of the sentence.
# vi / etc/network/interfaces...auto enp0s3iface enp0s3 inet dhcpup route add default gw 10.0.2.2 dev enp0s3auto enp0s8iface enp0s8 inet staticaddress 192.168.137.16netmask 255.255.255.0gateway 192.168.137.1up route del default dev enp0s8
Note: up route add default gw [gateway-addr] dev [dev-name]. In this statement, [dev-name] represents the name of the public network card, that is, the enp0s3 above, and [gateway-addr] indicates the gateway ip address used by the public network card.
So, how to get the gateway address of this external network card? The virtualbox stipulates as follows:
In NAT mode, the guest network interface is assigned to the IPv4 range 10.0.x.0/24 by default where x corresponds to the instance of the NAT interface + 2. So x is 2 when there is only one NAT instance active. In that case the guest is assigned to the address 10.0.2.15, the gateway is set to 10.0.2.2 and the name server can be found at 10.0.2.3.
To put it simply, if the 0th network card is a NAT network card, then the third number of its network segment is 10.0.2.0, and the gateway is 10.0.2.2 and the name server is 10.0.2.3. and so on.
Reference: link addr
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.