Multi-broadband networking (1) Using Macvlan in OpenWrt to realize single-line multi-dial Internet access

  When OpenWrt is running on a device (or computer) with only one WAN port, if there are multiple outgoing links at this time, you need to perform single-line multi-dial Internet access. Macvlan is not a VLAN in the traditional sense. It can be used to create a virtual network card to share the external network connected to the physical network card.

  In PPPoE dial-up or authentication network (such as campus network) , the service provider will limit the speed of each broadband user account, so as to ensure that all users can have a better network experience. If you want to log in to multiple user accounts at the same time, you need multiple network cards with different MACs. Through macvlan, many virtual network cards can be created, so that they can obtain different IP addresses and log in to different broadband accounts. Subsequent load balancing can be performed to increase the overall network speed.

Table of contents

1. Installation of Macvlan

 2. Configure Macvlan

1. Introduction to the network adapter owned by OpenWrt in this experiment

2. Create a macvlan virtual network card

3. Create a network interface


1. Installation of Macvlan

  Log in to the OpenWrt web management background, select the "System -> Software" menu, enter "macvlan" in "Filter", and install the software named "kmod-macvlan" in the search results, as shown in Figure 1. Note: If you can’t find any software, please click “Update lists” in “Operation” to update the software list. When updating, you need to ensure that the WAN interface card can be correctly connected to the WAN, and you need to create a wan interface in "Network->Interface" and configure it to access the Internet correctly.

Figure 1 OpenWrt software installation

 2. Configure Macvlan

1. Introduction to the network adapter owned by OpenWrt in this experiment

  This experiment is completed using a VMware virtual machine. The virtual machine where the OpenWrt system resides is allocated with two network cards, one network card (eth0) is bridged with the wired Ethernet card of the physical machine, and used as the WAN port network card; the other network card (eth1) only communicates with the physical machine, as the OpenWrt Used by the web management panel channel and the LAN port network card. Therefore, in this experiment, the WAN is accessed from eth0, and the LAN is provided from eth1 .

2. Create a macvlan virtual network card

  From the analysis in 1.2.1, we can see that the virtual network card needs to be based on the eth0 physical device, so as to connect to the WAN as a WAN port and perform broadband user authentication. Therefore, the Macvlan virtual network card needs to be based on the physical device eth0. Next, in the startup script, create a Macvlan virtual network card and enable the network card. After each boot, the system will automatically create and enable the network card.

  In the OpenWrt web management panel, select the "System -> Startup Items" menu, switch the upper tab to "Local Startup Script", and edit the local startup script, as shown in Figure 2.

Figure 2 Local startup script editing

  In the blank line above exit 0, enter the following command to create virtual macvlan network cards named vth0~vth7 based on the eth0 network card (lines 1~8), configure the MAC addresses of each network card (lines 9~16), and start each Network card (lines 17~24). Note: ① The MAC address of the virtual network card can be set by yourself or not specified. If not specified, the system will automatically generate a MAC address at random every time it is started. ②You can determine the number of virtual network cards by yourself according to your needs, instead of creating 8 virtual network cards in full imitation.

ip link add link eth0 name vth0 type macvlan
ip link add link eth0 name vth1 type macvlan
ip link add link eth0 name vth2 type macvlan
ip link add link eth0 name vth3 type macvlan
ip link add link eth0 name vth4 type macvlan
ip link add link eth0 name vth5 type macvlan
ip link add link eth0 name vth6 type macvlan
ip link add link eth0 name vth7 type macvlan
ifconfig vth0 hw ether 92:E8:D0:69:22:C0
ifconfig vth1 hw ether 32:2F:61:11:3B:69
ifconfig vth2 hw ether 96:6F:32:61:0B:F9
ifconfig vth3 hw ether DA:6E:10:26:0F:CB
ifconfig vth4 hw ether A6:B6:58:B3:B5:62
ifconfig vth5 hw ether 06:B1:DD:D7:3B:61
ifconfig vth6 hw ether 46:27:0A:B7:03:F6
ifconfig vth7 hw ether 1A:CE:E9:F7:3C:44
ifconfig vth0 up
ifconfig vth1 up
ifconfig vth2 up
ifconfig vth3 up
ifconfig vth4 up
ifconfig vth5 up
ifconfig vth6 up
ifconfig vth7 up

  After the input is complete, click the "Save" button in the lower right corner, and restart OpenWrt, and vth0~vth7 virtual macvlan network cards will be created automatically every time you restart.

3. Create a network interface

  In the OpenWrt web management panel, select the "Network->Interface" menu to enter the interface configuration page (Figure 3).

Figure 3 interface configuration page

  Click the "Create New Interface" button in the lower left corner, and the interface name can be specified by yourself. This experiment is "wan0" here. The device selects the vth0 virtual macvlan network card. If you use PPPoE dial-up to access the Internet, please select "PPPoE" in the protocol area, and if you use web authentication to access the Internet (such as campus network, etc.), please select DHCP client (Figure 4).

Figure 4 Create a new interface

  Click the "Create Interface" button in the lower right corner, and in the new page, switch to the "Advanced Settings" tab, and in the "Use Gateway Hop", specify the gateway hop, such as 10. Note: ① By default, the smaller the gateway hop point, the higher the priority. ② If you want to use mwan3 for load balancing in the future, the gateway hops of the network cards of vth0~vth7 must be different, and at this time the gateway hops are not necessarily related to the priority, but are configured according to the policy in the mwan3 balancing configuration.

Figure 5 Specify the gateway hop

  Switch to the "Firewall Settings" tab and select the firewall as the "wan" firewall. Please make sure that in the wan firewall configuration of the "Network->Firewall" menu, it can forward with the lan area.

For firewall configuration, see the fourth section of this article https://blog.csdn.net/Cx2008Lxl/article/details/122990497

Figure 6 Firewall configuration

   After the configuration is complete, click the "Save" button in the lower right corner.

  Repeat the above steps to create seven network interfaces wan0~wan7 in turn, the devices correspond to vth0~vth7 respectively, and the gateway hops are 10~17 in this experiment.

  So far, single line multi-dial configuration is complete. If you use PPPoE to access the Internet, and your carrier allows multi-dial, you should be able to see that wan0~wan7 have all obtained the IP addresses assigned by the ISP. If you use web authentication to access the Internet, you should be able to see that wan0~wan7 have all obtained the intranet IP assigned by the DHCP server.

  In the next section, we will configure the load balancing policies and rules for the eight created interfaces (wan0~wan7) to achieve an approximate "bandwidth superposition" effect.

Guess you like

Origin blog.csdn.net/Cx2008Lxl/article/details/123115782