On Linux, what is a veth device, why is it always created as a pair, and what happens when you attach one end of that pair to a Linux bridge device?
answer
- it is a cable, not a card
- half a cable makes no sense
- one end can move elsewhere
- the kernel already has a switch
- learned addresses, aged entries
basics
~20 sA veth is a virtual Ethernet device created in pairs acting like a patch cable: a frame transmitted on one end is received on the other. Attaching one end to a bridge makes it a port on an in-kernel layer-2 switch that learns MACs and forwards between ports.
solid answer
~50 sA veth — virtual Ethernet — is a kernel device that only exists in pairs, because its whole job is to be a pipe: whatever is transmitted on one end arrives as a received frame on the other. Creating one creates both, and deleting either destroys both. It matters because each end can be moved into a different network namespace, which is how an isolated environment gets a network interface with a real MAC address and a real address of its own while the other end stays in the host. That host-side end is normally enslaved to a Linux bridge with `ip link set <dev> master br0`. A bridge is a software layer-2 switch: it learns source MAC addresses into a forwarding database against the port they arrived on, forwards known unicast to that one port, and floods broadcast and unknown-unicast to all others. Both ends must be brought up, or the pair reports no carrier.
code
bash · 7 linesip link add br0 type bridge
ip link add veth0 type veth peer name veth0-br
ip link set veth0-br master br0
ip addr add 10.10.0.1/24 dev br0
ip link set br0 up
ip link set veth0 up
ip link set veth0-br upgo deeper
Know that a veth comes in pairs and behaves like a patch cable between two virtual NICs, and that a Linux bridge is a switch you can create in software. Remember to bring both ends up.
Explain the pair semantics precisely, describe enslaving a port with master, and walk through learning, forwarding and flooding in the bridge's forwarding database. Say why the address belongs on the bridge device.
Reason about the topology under failure: no-carrier from an unlifted peer, the smallest-MTU rule across bridge ports, and the lock-yourself-out risk when enslaving the NIC that carries the host's own address.
Own the choice of host network topology — bridged software switching versus routed or offloaded alternatives — weighing the CPU cost of software forwarding, observability of the resulting segment, and how much of it you want built by hand versus by tooling.
## The device `veth` stands for virtual Ethernet. It is a kernel network device whose defining property is that it does not exist alone: creation always yields two devices linked back to back, and iproute2 shows the relationship in the name, printing an end as something like `veth0@if12` where the number is the peer's interface index. ```bash ip link add veth0 type veth peer name veth0-br ``` The semantics are the simplest in the whole stack: a frame transmitted on one end is delivered to the receive path of the other, immediately, in the kernel. No wire, no encapsulation, no addressing decision. It behaves like a crossover cable soldered between two NICs. Delete one end and the other goes with it, because there is no meaningful half of a cable. Both ends behave like ordinary Ethernet devices in every other respect. Each gets a MAC address, each can carry IP addresses, each has an MTU you can set, each shows up with flags and an operational state. And critically, each can be **moved into a different network namespace**, which is the reason the device type exists: it is the standard way to give an isolated network environment a link back to somewhere else. One end stays in the host, the other is pushed into the isolated environment and renamed to something conventional. ## The bridge A veth pair by itself connects exactly two things. To connect many, you need a switch, and Linux has one built in: the bridge device. ```bash ip link add br0 type bridge ip link set veth0-br master br0 ``` A bridge is a layer-2 switch implemented in the kernel. Devices enslaved to it become its **ports**. Its behaviour is textbook switching: - **Learning.** When a frame arrives on a port, the bridge records the source MAC address against that port in its forwarding database. Entries age out after an inactivity timeout, so the topology can change without manual intervention. - **Forwarding.** A frame whose destination MAC is in the database is sent out that one port only. - **Flooding.** Broadcast frames, multicast, and unicast frames for an address not yet learned are sent to every port except the one they came in on. The bridge device itself is also a network device you can address. That is a distinction worth stating clearly: the *ports* are switch ports and do the layer-2 work; if the host needs an IP presence on that segment, you put the address on `br0` rather than on the enslaved port. An address left on a port that is enslaved will not participate in bridged forwarding the way people expect, and it is a frequent source of confusion. One consequence: enslaving an interface that currently carries the host's only address will cut you off, because the address is no longer where the traffic goes. Moving a physical NIC into a bridge is therefore a classic way to lock yourself out of a remote machine, and should be done as a single atomic reconfiguration. ## Putting the two together The standard topology is: one veth end inside the isolated environment with an address, the other end enslaved to a bridge in the host, and the bridge carrying the gateway address for that segment. Every isolated environment gets its own pair, all host-side ends land on the same bridge, and the bridge switches between them. From the kernel's point of view this is a perfectly ordinary Ethernet segment that happens to have no cables in it. This is the primitive that container and virtual-machine networking on Linux is assembled from, but the primitive itself is just a switch and some patch cables. ## The failure everyone hits first Both ends of a veth pair must be administratively up. Bring up only one and the pair has no carrier: the up end reports no carrier or an operational state of `LOWERLAYERDOWN`, because a veth's carrier is defined by its peer being up. The same applies to the bridge device — a bridge with no up ports has nothing to carry traffic. The symptom is an interface that looks configured, has an address, and passes nothing at all, which is why "did you bring up *both* ends?" is the first question to ask of any hand-built veth topology. A second gotcha is MTU. The bridge takes the smallest MTU among its ports, so one port left at a smaller MTU quietly constrains the whole segment. ## What an interviewer is testing Whether you understand these as kernel objects rather than as features of a product. Someone who has only used higher-level tooling will describe what a network *does*; someone who has built one by hand will describe the pair semantics, the enslavement, the learning table and the both-ends-up requirement — and will therefore be able to debug the topology when the tooling that normally builds it goes wrong.
- If you enslave a physical NIC to a bridge, where should the host's IP address live and why?On the bridge device, not on the enslaved NIC. Once the NIC is a bridge port it does layer-2 switching, and an address left on it no longer sits where traffic for the host is delivered. The practical consequence is that doing this over a remote session will cut you off unless the address move and the enslavement happen as one atomic change — which is exactly why this reconfiguration is normally scripted or done through the network manager rather than by hand.
- How does the bridge's MTU relate to the MTUs of its ports?The bridge takes the smallest MTU among its ports, because a switch cannot forward a frame that one of its links will not carry. One port left at a lower value therefore constrains the entire segment, and the symptom looks like a mysterious MTU problem in an environment where every other interface says 1500. When building a segment with a non-default MTU, set it consistently on every port and on the bridge itself.
- Why is a veth pair the standard way to connect an isolated network environment rather than just sharing the host's interface?Because each end is an independent device with its own MAC address, addresses and routing view, and one end can be moved into a separate network namespace. That gives the isolated environment a genuine interface of its own — it can be addressed, filtered and counted separately — while leaving the host in control of the other end. Sharing the host's interface would give no isolation at all, since there would be a single device and a single view of the network.
saying these in an interview costs you the question
- Thinks a single veth device can exist on its own
- Puts the IP address on the enslaved port instead of the bridge
- Brings up only one end and calls the pair broken
- Describes a bridge as doing routing between subnets
- Assumes the bridge needs manual forwarding entries to work