Linux Networking
Linux Networking
Linux Networking
Arie Bregman
Agenda
▪ Hello (Network) World
▪ ARP
▪ Interface Manipulation
▪ Network Troubleshooting
▪ Routing
▪ Network Bonding
▪ Network Namespaces
▪ Kernel Network Parameters
▪ Interview Questions
▪ Next Steps
▪ Resources
▪ Questions
Before we start...
▪ This presentation is not about learning networking concepts.
▪ Ask questions and start discussions as this is one of the best ways to learn.
Hello (Network) World
A world of flying packets
○ Yo
ping - test the reachability of a host
258 bytes from 8.8.8.8: icmp_seq=1 ttl=120 time=66.2 ms Will a packet size of
2000 will work?
● Control number of packets
● Don’t know which physical port a specific interface is using? Make the
interface led blinking!
● Tons of statistics!
*-network
description: Ethernet interface
product: Ethernet Connection (2) I219-LM
vendor: Intel Corporation
physical id: 1f.6
logical name: enp0s31f6
serial: 2b:12:55:17:25:c2
size: 1Gbit/s
capacity: 1Gbit/s
capabilities: bus_master cap_list ethernet physical tp 10bt 10bt-fd
configuration: autonegotiation=on driver=e1000e driverversion=3.2.6-k duplex=full
00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection (2) I219-LM (rev 31)
04:00.0 Network controller: Intel Corporation Wireless 8260 (rev 3a)
● It provides basic statistics like how many packets sent and received
ARP
Tell me your hardware address
Display ARP cache
● ARP is used for converting an IP address to a physical address
● ARP cache is where such coversion entries are stored
● You can also use ‘dev <device_name>’ to see ARP entries related to a specific
device
[arie@fedora ~]$ ip neigh add 2.2.2.2 lladdr 00:b1:6a:6a:11:c2 dev eth0 nud permanent
● You can remove a specific ARP entry by specifying the IP address and device
● You can also flush all the learned (not permanent) entries
Note: whenever you forget what argument you need to use, try using ‘man’
Commands
\ mentioned in this section
ping
ip a
ip l
lshw
lspci
ip neigh
The Basics - Exercise Solution
[arie@fedora ~]$ ip a
[arie@fedora ~]$ ping -c 3 -s 100 x.x.x.x
[arie@fedora ~]$ arp | grep <MAC>
[arie@fedora ~]$ ip neigh add 3.3.3.3 lladdr 00:b1:6b:6b:11:c6 dev eth0 nud permanent
Interfaces Manipulation
Time to break things
Network Manager
● The default manager for networking service in RHEL 7
● In older releases you might need to install the package ‘NetworkManager’
● You can also install a similar version on Ubuntu
dumdum: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
qlen 1000
link/ether 06:f1:a6:1b:c9:f5 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.50/24 scope global dumdum
valid_lft forever preferred_lft forever
Set broadcast address
● Set broadcast address
[arie@fedora ~]$ sudo ip addr add 192.168.0.50/24 broadcast 192.168.0.255 dev dumdum
Change MTU size
NAME="enp0s31f6"
MTU=”1800”
BOOTPROTO="static" # IMPORTANT
NAME="enp0s31f6"
MTU=”1800”
BOOTPROTO="static"
ETHTOOL_OPTS="speed 100”
Commands
\ mentioned in this section
ip link del/add
ip link set
ethtool -s eth0 speed <number>
nmcli connection reload
nmcli connection load <path>
Interfaces Manipulation - Exercise Solution
● Ethtool statistics
● Looking at /proc/net/dev
● Common arguments
○ -n to use IP addresses instead of hostname
○ -t to show only tcp connections
○ -p to show the pid of the program
○ -l to show only listening sockets
chrome 9827 abregman 133u IPv4 170 0t0 TCP localhost:57654->ec2-54om:https (ESTABLISHED)
● Side question: How to know which network services exists and what are their ports?
● You can see all the open files owned by a specific process
● Also known as
○ Packet Analyzer
○ Network sniffer
○ Packet Capture
● Allows you to
○ Monitor network usage and status
○ Analyze network problems
○ Verify security modifications
○ And so much more...
19:48:04.393650 IP 10.0.2.15.ssh > 10.0.2.2.34154: Flags [P.], seq 2880236:2880288, ack 5797, win
36192, length 52
19:48:04.393703 IP 10.0.2.15.ssh > 10.0.2.2.34154: Flags [P.], seq 2880288:2880340, ack 5797, win
36192, length 52
● Overwhelmed already? :)
Packet Sniffers - tcpdump
● Port range
Commands
\ mentioned in this section
lsof -i
netstat -tnlp
netstat -r
netstat -s
tshark
wireshark
tcpdump
Network Troubleshooting - Exercise Solution
● How it works?
○ Using TTL
○ First, it sends a packet with TTL=1. When the first router gets it, it
will exceed the TTL and so the router will drop the packet but will
reply to the sender with an exceed message
○ Then, the sender will increase TTL to 2 and send it again.
○ The process repeats until the packet arrived its destination
traceroute - usage
● First line in the output specifies the destination IP, number of maximal
hops and size of packets that will be used
● Rest of the lines describe: hop (name and IP) and packet round trip times
Start: 2018-09-05T15:45:32+0300
HOST: dblabla.ran.redhat.com Loss% Snt Last Avg Best Wrst StDev
1.|-- blabla.ran.redhat 0.0% 10 1.3 1.7 0.7 2.6 0.6
2.|-- 194.40.2.10 0.0% 10 22.8 37.6 12.1 94.5 36.0
3.|-- 190.55.2.1 0.0% 10 0.7 0.6 0.4 0.7 0.1
Network Bonding
Two are better than one
Network Bonding
● Bind two or more network interfaces together into a one logical interface
● Why?
○ Increasing bandwidth
○ Redundancy
● Requirements
○ Kernel bonding module
● Terminology
○ Master - the logical new interface
○ Slaves - the existing interfaces used for the bonding
Network Bonding - Modes
● Active Backup
○ Mode 1
○ Only one is active
○ Fault tolerance
● Balance XOR
○ Mode 2
○ Similar to mode 0 but based on MAC XOR’d with destination address
Network Bonding - Modes
● Broadcast
○ Mode 3
○ Data received by all interfaces
○ Fault Tolerance
● 802.3ad
○ Mode 4
○ Dynamic link aggregation
○ Slaves share the same properties
DEVICE=bond
TYPE=Bond
IPADDR…
● Configure slaves
○ vi /etc/sysconfig/network-scripts/ifcfg-eth0 (one of several slaves)
DEVICE=eth0
TYPE=Ethernet
SLAVE=yes
MASTER=bond
Network Bonding - How To in RHEL/CentOS/Fedora
● Define mode
○ vi /etc/modprobe.d/bonding.conf
auto eth0
iface eth0 inet manual
bond-master bond0
bond-primary eth0
auto eth1
iface eth1 inet manual
bond-master bond0
● List namespaces
ns1
● You can execute commands inside a network namespace with ‘ip nents exec’
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
● You can assign an interface from the default namespace to your newly created
namespace
● Perfect for namespace scenarios as it allows you to have one end in a network
namespace and the other in another network namespace or in the global
namespace
● Use the following command to see exactly how many parameters you can
change
● We’ll review some of the more common and interesting parameters you can change
○ For a full list (with an explanation) I recommend to visit the following site
Changing Kernel Parameters
● Obtain the value of a specific kernel parameter
● In order to turn our server into a kind of router, we need to enable packet
forwarding
● Note that this is not the only step required for turning our Linux server into a router
○ Modification of iptables rules is also needed but we’ll not cover it here
Ignore Broadcast Messages
\
Relevant commands
● Deep Dive
○ Routing
○ Packet Sniffers
● Iptables
○ Traditionally considered a security subject but has strong
connecting to networking
● Ethical Hacking
○ ARP spoofing
○ Route poisoning
● Computer-networking repository
○ Checklists
○ Videos
○ Interview Questions