Configuring VLANs on a Host for Proxmox VE
Configuring VLANs on a Host for Proxmox VEConfiguring VLANs on a Host for Proxmox VE.pngPic from unsplashIn today's increasingly complex networking environments, Virtual Local Area Networks (VLANs) have become a crucial tool for managing network traffic and ensuring optimal performance. This blog post provides a step-by-step guide on configuring VLANs on a host for Proxmox Virtual Environment (VE), a popular open-source virtualization platform.Why use VLANs with Proxmox VE?VLANs allow you to segregate network traffic into isolated broadcast domains, improving security and reducing network congestion. By configuring VLANs on a Proxmox VE host, you can:Improve network performance by reducing broadcast traffic.Enhance security by isolating sensitive virtual machines (VMs) and containers.Simplify network management and troubleshooting.PrerequisitesBefore proceeding, ensure you have the following:A Proxmox VE host installed and configured.A managed network switch that supports VLAN tagging (IEEE 802.1Q).Procedures:This guide provides procedures for configuring VLANs on a host for Proxmox Virtual Environment (VE). This guide provides instructions for configuring VLANs, with separate sections for both the command line interface (CLI) and the graphical user interface (GUI).The Command Line Interface (CLI) Configuration Step 1: A Proxmox VE host configurration Edit configuration file for the VLAN interface in /etc/network/interfaces.vi /etc/network/interfacesThe eno1 is a physical network interface and vmbr0 is a Linux Bridge.the following configuration, adjusting the address and gateway parameters as neededUse VLAN 2 for the Proxmox VE management IP with VLAN aware Linux bridgeauto lo iface lo inet loopback iface eno1 inet manual auto vmbr0.2 iface vmbr0.2 inet static address 10.2.2.254/24 gateway 10.2.2.1 auto vmbr0 iface vmbr0 inet static bridge-ports eno1 bridge-stp off bridge-fd 0 bridge-vlan-aware yes bridge-vids 1-4094Save the file and exit the editor use :wqApply the new configuration by restarting the networking service:systemctl restart networkingStep2: Configure a managed Network Switch In this scenario, use Cisco SG300-10P 10-Port Gigabit Managed Switch.The command "enable" is used to enter privileged EXEC mode on a Cisco SG300-10 switch, which allows access to configuration and management commands.enableThe subsequent command "configuration terminal" is used to enter global configuration mode, which allows the user to configure various aspects of the switch's behavior.configuration terminalThe command "interface gigabitethernet2" is used to select the Gigabit Ethernet interface 2 on the switch for configuration.The command "description VMS01" is used to assign a description to the selected interface, in this case labeling it as "VMS01", which standard for Virtual Machine Server.The command "switchport trunk allowed vlan add 2-4,11" is used to configure the selected interface as a trunk port and allow traffic from VLANs 2, 3, 4, and 11 to pass through the port. The "add" keyword specifies that these VLANs should be added to the existing list of allowed VLANs, if any.interface gigabitethernet2 description VMS01 switchport trunk allowed vlan add 2-4,11Step 3: Assign VLAN to VMs or Containers Finally, assign the newly created bridge to your VMs or containers:This sample use container.Select the desired container in the Proxmox VE web interface.Go to the Network tab.Click Edit.Select the bridge (e.g., vmbr0) from the Bridge dropdown menu.Assign a vlan number in VLAN TagClick OK to apply the changes.Repeat these steps for each container you want to assign to the VLAN.2023-03-24_141304.pngno VLAN as PVID vlan12023-03-24_141340.png2023-03-24_141414.pngGraphical User Interface (GUI) Configuration Step 1: Configure Proxmox VE Network Now, create a new Linux Bridge or Open vSwitch in the Proxmox VE web interface:Log in to the Proxmox VE web interface.Go to Datacenter > vms02 (your-node) > System > Network.Click "Create > Linux Bridge" or " Edit the Existing vmbr0 of Linux Bridge" (depending on your preference).Add the VLAN interface to the Bridge ports field.2023-03-24_133246.png2023-03-24_132715.png2023-03-24_133233.pngStep2: Configure a managed Network Switch 2023-03-24_095806.pngPVID (Default Vlan ID) as 12023-03-24_095945.pngConfigure the GE2 interface as a Trunk port and allow traffic from VLANs 2, 3, 4, and 11 to pass through the port, with VLAN1 as the Default Vlan without Vlan Tag.ConclusionBy following this guide, you've successfully configured VLANs on a Proxmox VE host and assigned them to your VMs and containers. This will help you optimize network performance, enhance security, and simplify network management in your virtual environment.Reference:https://pve.proxmox.com/wiki/Network_ConfigurationRelated:Proxmox VE 01 - 系統安裝篇遷移 VMware ESXi 的 ova 文件到 Proxmox 7.0PVE 的 LXC 容器系統安裝 CUPS 軟件，實現多平台共享的印表機PVE (Proxmox VE) 多網口的識別Proxmox VE 7 安裝Home Assistant虛擬機系統Managing LXC in Proxmox Virtual Environment (PVE)在 Ubuntu 中設置 VLAN
Setting a Static IP address in LinuxSetting a static IP address in Linux.pngIntroduction: Usually, IP addresses are dynamically assigned by the router's DHCP server on most network devices. But using a static IP address on the server makes the provided services more stable. If the DHCP server is not working, it will affect the computers in the local area network to obtain IP addresses, thereby affecting access to services, while servers with static IP addresses are not affected, so static IP is also necessary (on devices providing services).Table of Contents: Configuring a static IP address in RHEL/CentOS/Fedora:Setting a static IP address in Debian / Ubuntu (versions prior to 17.10):Setting a static IP address in Ubuntu (newer versions):Setting up VLAN in Ubuntu:Setting up Bridge in Debian:Bridge without VLANBridge with VLANConfiguring a static IP address in RHEL/CentOS/Fedora: To set a static IP address in RHEL / CentOS / FedoraFirst check the local network interface name:2022-03-18_121212.pngThe above figure shows that the network interface name of the local machine is eth0, representing the edited network file ifcfg-eth0Use nano or vim to edit:vim /etc/sysconfig/network-scripts/ifcfg-eth0Make changes to the ifcfg-eth0 file based on your own network:DEVICE="eth0" BOOTPROTO="static" DNS1="8.8.8.8" DNS2="1.1.1.1" GATEWAY="192.168.0.1" HOSTNAME="linux.kingtam.win" HWADDR="00:19:99:A4:46:AB" IPADDR="192.68.0.100" NETMASK="255.255.255.0" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="8105c095-799b-4f5a-a445-c6d7c3681f07"You need to edit the following settings:BOOTPROTO is dhcp (default) or static (static)DNS1 and DNS2 can use public DNS services such as 8.8.8.8, 1.1.1.1Gateway (GATEWAY) is the IP of the router or firewallHost name (HOSTNAME) customizableNetwork mask (NETMASK) is usually 255.255.255.0 (/24) modify according to your own network parametersIP address (IPADDR) the local IP addressONBOOT whether to start automatically is yes or noThen edit: resolve.confresolve.conf is used to set the definitions of each item when the DNS client requests name resolution.vim /etc/resolv.confnameserver 8.8.8.8 # Modify with your preferred DNS address nameserver 1.1.1.1 # Modify with your preferred DNS addressUse one of the following commands to restart the network and apply all settings:/etc/init.d/network restartsystemctl restart networkSetting a static IP address in Debian / Ubuntu (versions prior to 17.10): To set a static IP address in Debian/Ubuntu (versions prior to 17.10), open the following file:vim /etc/network/interfacesThe default is dhcp: no-auto-down eth0 # or possibly auto eth0 iface eth0 inet dhcpEdit using nano or vim, and make changes based on your own network:no-auto-down eth0 iface eth0 inet static address 192.168.0.100 netmask 255.255.255.0 gateway 192.168.0.1 dns-nameservers 1.1.1.1 dns-nameservers 8.8.8.8The following settings need to be edited:Change iface eth0 inet dhcp (default) to iface eth0 inet static (static)dns-nameservers can have multiple values, such as using public DNS services like 8.8.8.8, 1.1.1.1gateway is the IP address of the router or firewallnetmask is usually 255.255.255.0 (/24), adjust according to your own network parametersaddress is the IP address of the local machineAfter saving the interfaces settings, edit /etc/resolv.conf:vim /etc/resolv.conf nameserver 8.8.8.8 # Modify with your preferred DNS address nameserver 1.1.1.1 # Modify with your preferred DNS addressUse one of the following commands to restart the network and apply all settings:/etc/init.d/network restartsystemctl restart networkSetting a static IP address in Ubuntu (newer versions): Starting from Ubuntu 17.10, Netplan is the default network management tool.Network configuration files are stored in *.yaml files in the directory /etc/netplan/.In my case, it is /etc/netplan/00-installer-config.yaml, and the default content is:network: ethernets: eth0: dhcp4: true version: 2Edit the 00-installer-config.yaml configuration file using nano or vim:network: version: 2 renderer: networkd ethernets: eth0: dhcp4: no addresses: [192.168.1.2/24] routes: - to: default via: 192.168.1.1 nameservers: addresses: [8.8.8.8,1.1.1.1]You need to edit the following settings:renderer: networkd specifies that this interface is managed by the systemd-networkd servicedhcp4: no changes to manual static IP address setupaddresses the local IP address and network segmentnameservers DNS serveraddresses [8.8.8.8,1.1.1.1] can be multiple IP addressesSave the 00-installer-config.yaml settings.Apply the network settings using the following command:netplan applySetting up VLAN in Ubuntu: In this example, N1 is flashed with Armbian, and the network port is connected to the trunk port of the switch.Dynamically obtain an IP addressThe network configuration files are stored in *.yaml files in the /etc/netplan/ directory.The default content of /etc/netplan/armbian-default.yaml is:network: version: 2 renderer: NetworkManagerEdit the /etc/netplan/armbian-default.yaml configuration file using nano or vim:network: version: 2 renderer: NetworkManager ethernets: eth0: dhcp4: true vlans: vlan.3: id: 3 link: eth0 dhcp4: trueThe configuration file is written in YAML format, and various settings are included:The "version: 2" in the first line specifies the YAML version used in this file.The "renderer" field specifies the network management tool to be used, which in this case is "NetworkManager", a popular tool for managing networks on Linux systems.In the "ethernets" section, the "eth0" physical interface is configured, and the interface is set to obtain an IPv4 address via DHCP.In the "vlans" section, the VLAN (Virtual Local Area Network) interface on the "eth0" network interface is configured. The VLAN ID is 3 and is connected to the physical interface "eth0" via the "link" field. The VLAN interface is also configured to obtain an IPv4 address via DHCP.This configuration file sets up a network connection where both the physical interface "eth0" and the VLAN interface obtain dynamic IP addresses via DHCP.Set static IP address version: 2 renderer: NetworkManager ethernets: eth0: dhcp4: false vlans: vlan.3: id: 3 link: eth0 dhcp4: no addresses: [10.3.3.3/24] routes: - to: default via: 10.3.3.1 nameservers: addresses: [8.8.8.8,1.1.1.1]The VLAN configuration sets up a new interface vlan.3 with ID 3 associated with eth0. Its dhcp4 is set to no, with the static IP address 10.3.3.3 and subnet mask 24. The default route is specified through IP address 10.3.3.1, and 8.8.8.8 and 1.1.1.1 are set as DNS servers.Setting up Bridge in Debian: Without VLANTo find out the default network interface name of the machine, use the following command:ip -c route | head -n 1 | cut -d ' ' -f 5eth0Edit the network interface via text editorsudo vim /etc/network/interfacesi. As DHCP:source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # Wired adapter #1 allow-hotplug eth0 no-auto-down eth0 # Bridge as DHCP auto br0 iface br0 inet dhcp bridge_ports eth0Then restart the networking service:sudo systemctl restart networking.servicei. As Static:source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # Wired adapter #1 allow-hotplug eth0 no-auto-down eth0 # Bridge setup to static IP auto br0 iface br0 inet static address 10.1.1.10 broadcast 10.1.1.255 netmask 255.255.255.0 gateway 10.1.1.1 bridge_ports eth0 bridge_stp off # disable Spanning Tree Protocol bridge_waitport 0 # no delay before a port becomes available bridge_fd 0 # no forwarding delayThen restart the networking service:sudo systemctl restart networking.serviceWith VLAN (Advanced Example)Make sure the vlan package is installed on the system:sudo apt install vlan -yIf the host is a hypervisor consider adding below sysctl configurations:echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf echo "net.ipv4.conf.all.arp_filter=0" | sudo tee -a /etc/sysctl.conf echo "net.ipv4.conf.all.rp_filter=2" | sudo tee -a /etc/sysctl.confLoad configurations:$ sudo sysctl -pnet.ipv4.ip_forward = 1net.ipv4.conf.all.arp_filter = 0net.ipv4.conf.all.rp_filter = 2Then modify interfaces configurations:sudo vim /etc/network/interfacesThe interface content is as follow:source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # Wired adapter #1 allow-hotplug eth0 iface eth0 inet manual pre-up ifconfig $IFACE up pre-down ifconfig $IFACE down # VLAN 3 auto eth0.3 iface eth0.3 inet manual # Bridge br0 auto br0 iface br0 inet static bridge_ports eth0.3 bridge_stp off bridge_waitport 0 bridge_fd 0 address 10.3.3.3 netmask 255.255.255.0 gateway 10.3.3.1 dns-nameservers 1.1.1.1 8.8.4.4Then restart the networking service:sudo systemctl restart networking.serviceConclusion: Each Linux distribution may have different methods for setting a static IP address, but the process is generally similar.Reference: How to Set Static IP Address and Configure Network in Linux (tecmint.com)如何在Ubuntu Server 18.04 LTS中配置靜態IP地址 - soso101 - 博客園 (cnblogs.com)Create Linux Bridge on VLAN Interface in Debian 11/10
ZeroTier 新增 Moon節點zerotier_logo_black.png前言:ZeroTier實在是是太優秀，設定簡單，可以應用於多個網絡環境互通(我理解為內網穿透)。因為ZeroTier根伺服器在海外，高峰用量時段連線會有不穩定，所以搭建Moon節點可以作為一個中轉站，彌補線路的的不足。條件限制:在已使用的ZeroTier 點對點虛擬網絡內建立Moon節點節點伺服器需要公網連線及開通 9993 端口(PORT)開始部署:在公網的伺服器上安裝ZeroTier2021-09-27_114407.pngsudo curl -s https://install.zerotier.com | sudo bash在Zerotier控制中心 查看NETWORK ID2021-09-27_114509.png在公網的伺服器上加入到ZeroTier虛擬網絡2021-09-27_114933.pngsudo zerotier-cli join 565799d8fxxxxxxx在Zerotier控制中心 允許加入2021-09-27_115053.png選取後，可獲得分配的虛擬網絡IP地址配置Moon進入到ZeroTier所在的目錄cd /var/lib/zerotier-one/生成 moon.json 配置文件zerotier-idtool initmoon identity.public >> moon.json編輯 moon.json 配置文件2021-09-27_115538.pngsudo vi moon.json將配置文件中的 "stableEndpoints": [] 修改成 "stableEndpoints": ["PublicIP/9993"]，將 PublicIP 替換成雲服務器的公網IP。建立 000000*.moon 簽名文件：sudo zerotier-idtool genmoon moon.json新建 moons.d 目錄，並將 000000*.moon 文件移動到其目錄下：sudo mkdir moons.d sudo mv 000000*.moon moons.d* 代表節點id，我這裡00000019b9e0bc9d.moon。重啟ZeroTier服務sudo systemctl restart zerotier-one(ZeroTier客戶端)加入到Moon節點Linux系統添加Moon節點查看可加入的節點id2021-09-28_083920.pngsudo zerotier-cli peers | grep -i 'moon'這裡查看到的節點是19b9e0bc9d加入到Moon節點2021-09-28_083138.pngsudo zerotier-cli orbit 19b9e0bc9d 19b9e0bc9d重啟ZeroTier服務使之生效/etc/init.d/zerotier restart或者sudo systemctl restart zerotier-oneWindows系統添加Moon節點系統管理員身份開啟PowerShell2021-09-27_120257.png查看可加入的節點id2021-09-28_113719.pngzerotier-cli.bat peers | Select-String "MOON"查看到的節點是19b9e0bc9d加入到Moon節點2021-09-27_120355.pngzerotier-cli.bat orbit 19b9e0bc9d 19b9e0bc9d重啟電腦使之ZeroTier服務生效手動添加Moon節點在ZeroTier 程序的目錄建立moons.d資料夾，將 000000*.moon 簽名文件復制到該資料夾中。以Windows10為範例:Windows10的 ZeroTier 目錄位置: %PROGRAMDATA%\ZeroTier\One2021-09-29_104330.png新增moons.d目錄2021-09-29_104654.png將Moon節點的簽名文件 000000*.moon 復制到該目錄中。重啟電腦或者服務使之ZeroTier服務生效[tip type="red"]以下是各個系統下 ZeroTier 目錄位置 ：Macintosh: /Library/Application Support/ZeroTier/One Linux: /var/lib/zerotier-one FreeBSD/OpenBSD: /var/db/zerotier-one[/tip]參考資料:ZeroTier 搭建 moon 服務器簡單搭建 Zerotier Moon 為虛擬網絡加速Private Root Servers