Networking Flashcards
Command: List and Modify Interfaces
ip link
- OR -
ip -n <NAMESPACE> link</NAMESPACE>
Command: List IP Addresses on an Interface
ip addr
Command: Set IP Address on an Interface
ip addr add <CIDR> dev eth0
/etc/network/interfaces</CIDR>
Command: View Routing Table
ip route
Command: Add entries into the Route Table
ip route add (CIDR) via (GATEWAYIP)
Location: Where IP Forwarding is set
/proc/sys/net/ipv4/ip_forward
Location: Where DNS Name Server is set
/etc/resolv.conf
Location: Where DNS Order is set
hosts: files dns
Command: List Network Namespaces
ip netns
Command: Add Network Namespace
ip netns add <NAMESPACE></NAMESPACE>
Command: Add a Virtual Interface between Namespaces
1) ip link add <VIRTINTERFACENAME1> type veth peer name <VIRTINTERFACENAME2>
2) ip link set <VIRTINTERFACENAME1> netns <NAMESPACE1>
3) ip link set <VIRTINTERFACENAME2> netns <NAMESPACE2>
4) ip -n <NAMESPACE1> addr add <IPADDR1> dev <VIRTINTERFACENAME1>
5) ip -n <NAMESPACE2> addr add <IPADDR2> dev <VIRTINTERFACENAME2>
6) ip -n <NAMESPACE1> link set <VIRTINTERFACENAME1> up
7) ip -n <NAMESPACE2> link set <VIRTINTERFACENAME2> up</VIRTINTERFACENAME2></NAMESPACE2></VIRTINTERFACENAME1></NAMESPACE1></VIRTINTERFACENAME2></IPADDR2></NAMESPACE2></VIRTINTERFACENAME1></IPADDR1></NAMESPACE1></NAMESPACE2></VIRTINTERFACENAME2></NAMESPACE1></VIRTINTERFACENAME1></VIRTINTERFACENAME2></VIRTINTERFACENAME1>
Command: Execute on Namespace
ip -n <NAMESPACE> link ping <IPADDR></IPADDR></NAMESPACE>
Command: Create a NAT Gateway
iptables -t nat -A POSTROUTING -s <CIDR> -j MASQUERADE</CIDR>
Command: Port Forwarding Rule
iptables -t nat -A PREROUTING –dport 80 –to-destination <IPADDR:PORT> -j DNAT</IPADDR:PORT>
Command: Display IP Address to MAC Address Mapping
arp
Command: Install Weave Net
kubectl apply -f “https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d ‘\n’)”
Command: setting up a Linux Bridge
1) ip link add v-net-0 type bridge # Create Linux Bridge (virtual internal network)
2) ip link set dev v-net-0 up # Bring up the bridge interface
3) ip addr add 192.168.15.5/24 dev v-net-0 # Set CIDR for the internal network
4) ip link add veth-red type veth peer name veth-red-br # Create veth linked pair
5) ip link set veth-red netns red # Create the red namespace and attach veth-red
6) ip -n red addr add 192.168.15.1 dev veth-red # Set IP Address for veth-red in the red NS
7) ip -n red link set veth-red up # Bring up the veth-red-br in the red NS
8) ip link set veth-red-br master v-net-0 # Attach veth-red-br to the bridge
9) ip netns exec blue ip route add 192.168.1.0/24 via 192.168.15.5 # Add CIDR to Route Table in blue NS
10) iptables -t nat -A POSTROUTING -s 192.168.15.0/24 -j MASQUERADE # Create a NAT Gateway
Location: Container Network Interface (CNI) Configuration
In /etc/kubernetes/manifests/kubelet.yaml
–network-plugin=cni
–cni-bin-dir=/opt/cni/bin
–cni-conf-dir=/etc/cni/net.d