Add use case for Bond example
[pve-docs.git] / pve-network.adoc
CommitLineData
0bcd1f7f
DM
1Network Configuration
2---------------------
3include::attributes.txt[]
4
5{pve} uses a bridged networking model. Each host can have up to 4094
6bridges. Bridges are like physical network switches implemented in
7software. All VMs can share a single bridge, as if
8virtual network cables from each guest were all plugged into the same
9switch. But you can also create multiple bridges to separate network
10domains.
11
12For connecting VMs to the outside world, bridges are attached to
13physical network cards. For further flexibility, you can configure
14VLANs (IEEE 802.1q) and network bonding, also known as "link
15aggregation". That way it is possible to build complex and flexible
16virtual networks.
17
8c1189b6
FG
18Debian traditionally uses the `ifup` and `ifdown` commands to
19configure the network. The file `/etc/network/interfaces` contains the
20whole network setup. Please refer to to manual page (`man interfaces`)
0bcd1f7f
DM
21for a complete format description.
22
23NOTE: {pve} does not write changes directly to
8c1189b6
FG
24`/etc/network/interfaces`. Instead, we write into a temporary file
25called `/etc/network/interfaces.new`, and commit those changes when
0bcd1f7f
DM
26you reboot the node.
27
28It is worth mentioning that you can directly edit the configuration
29file. All {pve} tools tries hard to keep such direct user
30modifications. Using the GUI is still preferable, because it
31protect you from errors.
32
5eba0743 33
0bcd1f7f
DM
34Naming Conventions
35~~~~~~~~~~~~~~~~~~
36
37We currently use the following naming conventions for device names:
38
39* Ethernet devices: eth[N], where 0 ≤ N (`eth0`, `eth1`, ...)
40
41* Bridge names: vmbr[N], where 0 ≤ N ≤ 4094 (`vmbr0` - `vmbr4094`)
42
43* Bonds: bond[N], where 0 ≤ N (`bond0`, `bond1`, ...)
44
45* VLANs: Simply add the VLAN number to the device name,
46 separated by a period (`eth0.50`, `bond1.30`)
47
48This makes it easier to debug networks problems, because the device
49names implies the device type.
50
51Default Configuration using a Bridge
52~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53
54The installation program creates a single bridge named `vmbr0`, which
55is connected to the first ethernet card `eth0`. The corresponding
8c1189b6 56configuration in `/etc/network/interfaces` looks like this:
0bcd1f7f
DM
57
58----
59auto lo
60iface lo inet loopback
61
62iface eth0 inet manual
63
64auto vmbr0
65iface vmbr0 inet static
66 address 192.168.10.2
67 netmask 255.255.255.0
68 gateway 192.168.10.1
69 bridge_ports eth0
70 bridge_stp off
71 bridge_fd 0
72----
73
74Virtual machines behave as if they were directly connected to the
75physical network. The network, in turn, sees each virtual machine as
76having its own MAC, even though there is only one network cable
77connecting all of these VMs to the network.
78
79
80Routed Configuration
81~~~~~~~~~~~~~~~~~~~~
82
83Most hosting providers do not support the above setup. For security
84reasons, they disable networking as soon as they detect multiple MAC
85addresses on a single interface.
86
87TIP: Some providers allows you to register additional MACs on there
88management interface. This avoids the problem, but is clumsy to
89configure because you need to register a MAC for each of your VMs.
90
8c1189b6 91You can avoid the problem by ``routing'' all traffic via a single
0bcd1f7f
DM
92interface. This makes sure that all network packets use the same MAC
93address.
94
8c1189b6 95A common scenario is that you have a public IP (assume `192.168.10.2`
0bcd1f7f 96for this example), and an additional IP block for your VMs
8c1189b6 97(`10.10.10.1/255.255.255.0`). We recommend the following setup for such
0bcd1f7f
DM
98situations:
99
100----
101auto lo
102iface lo inet loopback
103
104auto eth0
105iface eth0 inet static
106 address 192.168.10.2
107 netmask 255.255.255.0
108 gateway 192.168.10.1
109 post-up echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp
110
111
112auto vmbr0
113iface vmbr0 inet static
114 address 10.10.10.1
115 netmask 255.255.255.0
116 bridge_ports none
117 bridge_stp off
118 bridge_fd 0
119----
120
121
8c1189b6
FG
122Masquerading (NAT) with `iptables`
123~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0bcd1f7f
DM
124
125In some cases you may want to use private IPs behind your Proxmox
126host's true IP, and masquerade the traffic using NAT:
127
128----
129auto lo
130iface lo inet loopback
131
132auto eth0
133#real IP adress
134iface eth0 inet static
135 address 192.168.10.2
136 netmask 255.255.255.0
137 gateway 192.168.10.1
138
139auto vmbr0
140#private sub network
141iface vmbr0 inet static
142 address 10.10.10.1
143 netmask 255.255.255.0
144 bridge_ports none
145 bridge_stp off
146 bridge_fd 0
147
148 post-up echo 1 > /proc/sys/net/ipv4/ip_forward
149 post-up iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o eth0 -j MASQUERADE
150 post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o eth0 -j MASQUERADE
151----
152
b4c06a93
WL
153
154Linux Bond
155~~~~~~~~~~
156
157Bonding is a technique for binding multiple NIC's to a single network
158device. It is possible to achieve different goals, like make the
159network fault-tolerant, increase the performance or both
160together.
161
162There are 7 modes for bonding:
163
164* *Round-robin (balance-rr):* Transmit network packets in sequential
165order from the first available network interface (NIC) slave through
166the last. This mode provides load balancing and fault tolerance.
167
168* *Active-backup (active-backup):* Only one NIC slave in the bond is
169active. A different slave becomes active if, and only if, the active
170slave fails. The single logical bonded interface's MAC address is
171externally visible on only one NIC (port) to avoid distortion in the
172network switch. This mode provides fault tolerance.
173
174* *XOR (balance-xor):* Transmit network packets based on [(source MAC
175address XOR'd with destination MAC address) modulo NIC slave
176count]. This selects the same NIC slave for each destination MAC
177address. This mode provides load balancing and fault tolerance.
178
179* *Broadcast (broadcast):* Transmit network packets on all slave
180network interfaces. This mode provides fault tolerance.
181
182* *IEEE 802.3ad Dynamic link aggregation (802.3ad)(LACP):* Creates
183aggregation groups that share the same speed and duplex
184settings. Utilizes all slave network interfaces in the active
185aggregator group according to the 802.3ad specification.
186
187* *Adaptive transmit load balancing (balance-tlb):* Linux bonding
188driver mode that does not require any special network-switch
189support. The outgoing network packet traffic is distributed according
190to the current load (computed relative to the speed) on each network
191interface slave. Incoming traffic is received by one currently
192designated slave network interface. If this receiving slave fails,
193another slave takes over the MAC address of the failed receiving
194slave.
195
196* *Adaptive load balancing (balanceIEEE 802.3ad Dynamic link
197aggregation (802.3ad)(LACP):-alb):* Includes balance-tlb plus receive
198load balancing (rlb) for IPV4 traffic, and does not require any
199special network switch support. The receive load balancing is achieved
200by ARP negotiation. The bonding driver intercepts the ARP Replies sent
201by the local system on their way out and overwrites the source
202hardware address with the unique hardware address of one of the NIC
203slaves in the single logical bonded interface such that different
204network-peers use different MAC addresses for their network packet
205traffic.
206
207For the most setups the active-backup are the best choice or if your
208switch support LACP "IEEE 802.3ad" this mode should be preferred.
209
cd1de2c2
WL
210The following bond configuration can be used as distributed/shared
211storage network. The benefit would be that you get more speed and the
212network will be fault-tolerant.
213
b4c06a93
WL
214.Example: Use bond with fixed IP address
215----
216auto lo
217iface lo inet loopback
218
219iface eth1 inet manual
220
221iface eth2 inet manual
222
223auto bond0
224iface bond0 inet static
225 slaves eth1 eth2
226 address 192.168.1.2
227 netmask 255.255.255.0
228 bond_miimon 100
229 bond_mode 802.3ad
230 bond_xmit_hash_policy layer2+3
231
232auto vmbr0
233iface vmbr0 inet static
234 address 10.10.10.2
235 netmask 255.255.255.0
236 gateway 10.10.10.1
237 bridge_ports eth0
238 bridge_stp off
239 bridge_fd 0
240
241----
242
cd1de2c2
WL
243
244Another possibility it to use the bond directly as bridge port.
245This can be used to make the guest network fault-tolerant.
246
247.Example: Use a bond as bridge port
b4c06a93
WL
248----
249auto lo
250iface lo inet loopback
251
252iface eth1 inet manual
253
254iface eth2 inet manual
255
256auto bond0
257iface bond0 inet maunal
258 slaves eth1 eth2
259 bond_miimon 100
260 bond_mode 802.3ad
261 bond_xmit_hash_policy layer2+3
262
263auto vmbr0
264iface vmbr0 inet static
265 address 10.10.10.2
266 netmask 255.255.255.0
267 gateway 10.10.10.1
268 bridge_ports bond0
269 bridge_stp off
270 bridge_fd 0
271
272----
273
0bcd1f7f
DM
274////
275TODO: explain IPv6 support?
276TODO: explan OVS
277////