SlideShare a Scribd company logo
Linux For Embedded Systems
ForArabs
Ahmed ElArabawy
Course 102:
UnderstandingLinux
Lecture 20:
Networking in Linux (Basic Concepts)
Why Networking ??
• Networking is a very essential tool for Linux Users/developers
• Setup our machine to be able to connect to the internet
• Identify our machine information (interfaces/IP Address/ …)
• Copy files to/from remote machines
• Copy files to/from the web
• Remotely access a remote machine
• And Other important tasks….
Why Networking ??
• For an embedded developer, networking is even much more
essential
• Embedded Systems normally comes without a display, and we
will need to connect to it via a host machine
• We will need to connect to the embedded target for:
• Reading the logs
• Debugging the program
• Setting some configuration files
• Uploading a new image
So ….
• Networking to an embedded user/developer aims for two
main purposes
• Connect to a remote machine or to the internet
• This is typically done using an Ethernet connection
• Connect a host machine to the embedded target
• This can be achieved via,
• JTAG Connection
• Serial Console Connection
• Ethernet Connection
Networking Basics
Network Interfaces
• The computer/board may have one or more network
interfaces
• In Hardware, this is represented by,
• An Ethernet NIC card
• WiFi port
• In Linux, each interface will have a name,
• Examples (eth0, eth1, …. )
Showing the Network Interfaces
(ifconfig Command)
$ ifconfig
$ ifconfig <interface name> [up/down]
• This command is responsible for showing and managing
interfaces
• To show the interfaces in the system
$ ifconfig
$ ifconfig -s (shows an abstract description)
• To show info about a specific interface
$ ifconfig eth1
• To activate/deactivate
$ ifconfig eth1 up
$ ifconfig eth2 down
Showing the Network Interfaces
(ifconfig Command)
The MAC Address
• The MAC address is also called the Hardware Address
• It is a unique address for each NIC card (set by the
manufacturer)
• It is a 48 bit number written in hexadecimal format (4 bit
digits) as follows,
68:05:CA:03:19:9C
• Note,
• Hexadecimal format is a format that converts every 4 bits into a
single digit
• Since 4 bits require 16 combinations (takes values from 0 – 15),
the digits (0-9, A,B,C,D,E,F) are used
• Accordingly, since the MAC address is 48 bits, it will be written in
12 hexadecimal digits
MAC Address
MAC Address
00:0C:F1:AC:34:F1
Manufacturer = Intel
0000:0000
Unicast Address
Globally Unique
Local Area Network
Local Area Network
• A Local Area Network (LAN) is a set of computers connected
together via hub/switch
• The devices (computers) are located in the same area (locally
located)
• The computers have the same type of network interface
(Ethernet, Wifi, …)
• Data is transferred between the machines based on their MAC
addresses
A Real Network
A Real Network
• In a more realistic network, not all computer reside in the
same LAN,
• Limitation on distance between the devices
• Different kind of requirements (Wired/wireless/…)
• Need to isolated devices in groups
• Other…
• Hence A typical network is composed of a group of LANs
interconnected with each other with some routing devices
• Within each LAN, MAC address is used for communication
inside this LAN
• However, the MAC Address is no longer enough to
communicate between the devices in different LANs, and we
need a more global addressing scheme
• This is called network addressing which uses the IP Address
IP Address
• Any network interface on a machine in the network is
identified by its IP Address
• Sometimes the interface may have multiple IP-Addresses
• The IP address is composed of 4 numbers (0-255) separated
by a dot
• Example: 192.168.101.112
• This is assuming, we are using IPv4, another version which is IPv6
has a different format
• Note that the number 0-255 is an 8 bit number
IP Address
192.168.101.112
11000000 10101000 1100101 1110000
Is IP Address Enough ??
• Port numbers identify different services within the same IP
Address
• Each connection will have both source port and destination
port numbers
Port Numbers
Subnet
• To Facilitate Routing,
• The machines are organized into small networks (subnets)
• Subnets share the upper part of the IP address
132.201.1.100
132.201.1.101
132.201.1.102
132.201.1.103
132.201.1.104
132.201.2.100
132.201.2.101
132.201.2.103
132.201.2.102
132.201.2.104
132.201.3.100
132.201.3.101
132.201.3.102
132.201.3.103
132.201.3.104
Subnet
Subnet
• Network interfaces within the same subnet share the upper
part of the IP address, and differ in the lower part
• The number of bits shared within the subnet control the
subnet size
• For example if we have the upper 24 bits (3 bytes) shared
within the subnet, then the interfaces with the subnet can
differ in 8 bits only, which leads to a maximum of 256
addresses
• If the shared part is reduced to 20 bits only, we will have 12
bits to change which lead to 4096 different addresses
• The part of the IP Address shared among the interfaces within
the subnet, is expressed as the subnet mask
Subnet Mask
192.168.101.112
11000000 10101000 01100101 01110000
Subnet Mask
192.168.101.112
11000000 10101000 01100101 01110000
Subnet Address : 192.168.101.0
Subnet Mask : 255.255.255.0
Address : 192.168.101.112/24
Subnet Mask
192.168.101.112
11000000 10101000 01100101 01110000
Subnet Address : 192.168.96.0
Subnet Mask : 255.255.240.0
Address : 192.168.101.112/19
Subnet Mask
Subnet Mask: 255.255.255.0
Subnet Mask: 255.255.255.0
Subnet Mask: 255.255.255.0
Course 102: Lecture 20: Networking In Linux (Basic Concepts)
Show Subnet Mask
(ifconfig Command)
$ ifconfig
IP Address Allocation
• IP Address can be allocated in two different ways,
• Statically allocated
• This is done manually, or via a startup script
• Address is always the same
• Dynamically allocated via a DHCP server
• At startup, the machine asks a DHCP server to provide it with an IP
Address
• The DHCP server responds with an unused IP address within the proper
subnet
• Hence, the IP address can change every time the machine boots
• The DHCP server can be configured so it will always assign a specific
machine the same IP Address
• Using DHCP address allocation is more convenient and more flexible
• Since the DHCP server needs to be accessed before the IP address is
allocated, it should reside within the same LAN as the machines (it is
typically located inside the LAN switch)
Allocating IP Address
(ifconfig Command)
$ ifconfig <interface> <IP Address>
$ ifconfig <interface> <IP Address> netmask <netmask>
$ ifconfig <interface> netmask <netmask>
Used to statically allocate IP address to an Interface and/or set
its net-mask
• Example:
$ ifconfig eth1 192.268.0.10
$ ifconfig eth1 netmask 255.255.255.224
$ ifconfig eth1 192.268.0.10 netmask 255.255.255.224
Special IP Addresses
• Some IP Addresses have a special meaning,
• The Address 127.0.0.1 is reserved for the Local Host. This means it is
used as a loop back address
• Any address ending with all ones (after the subnet mask), is a
broadcast address within this subnet
• Example,
In the Subnet 192.168.224.0/19 the broadcast address would be, 192.168.255.255
• Any address of the format xxx.xxx.xxx.1 is reserved for the default
gateway
• The following subnets are reserved for private addressing (to be
discussed later)
Subnet Starting from Ending at
10.0.0.0/8 10.0.0.0 10.255.255.255
172.16.0.0/12 172.16.0.0 172.31.255.255
192.168.0.0/16 192.168.0.0 192.168.255.255
OK…So How is Routing Done ??
OK…So How is Routing Done ??
OK…So How is Routing Done ??
• First the destination address is checked to be within the same
subnet of the sender or not
• If it is on the same subnet,
• Then delivering the packet will need to be done based on the MAC
address
• This means we will need to know the MAC address of the destination
• We will not need this now, since the destination address does not
belong to the sender subnet
• If it is not on the same subnet,
• Then we will need to deliver the packet to the proper next hop
• The next hop is identified based on the Routing Table
• The routing table is a table of routes that identifies the next hop
based on the packet destination
OK…So How is Routing Done ??
Show the Routing Table
(route Command)
$ route
• The route command shows the entries of the routing table
$ route
• Each route contains,
• Destination: This is an address, whether a host address or a subnet
address
• Network mask: Used when a subnet address is used for destination
• Interface: The used interface for this destination
• Gateway: The next hop for this destination
• Upon the reception of a packet,
• Linux tests the packet destination address to match the destination
of the routes
• If a match exists, Linux forwards the packet to the defined interface,
towards the specified GW address
Show the Routing Table
(route Command)
Manage Routing Table
(route command)
$ route add <address> dev <interface> gw <address>
$ route add default gw <address>
$ route del <address>
$ route del default
• To add a route
$ sudo route add 192.56.76.123 dev eth1 gw 192.168.101.1
$ sudo route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0
$ sudo route add default gw 192.168.101.1
• To delete a route
$ sudo route del default
$ sudo route del 192.168.100.20
OK…So How is Routing Done ??
OK…So how is Routing Done ??
• Now the router has received the packet
• It should also check its routing table to identify the proper
interface to use for forwarding the packet
• The destination is found to belong to the subnet
141.14.2.0/24, and the interface is identified
• Now we need to deliver the packet to its destination within
the subnet
• Since delivering the packet within the subnet is based on the
MAC Address, we will need to know the MAC address of the
destination
What is the MAC Address for the Host 141.14.2.105 ???
Identifying the MAC Address …
(The ARP Protocol)
• The machine should have a table that maps IP Addresses to
MAC addresses within its subnet
• This table is called the ARP table
• If the machine does not have the address in its table, it
queries it using the ARP protocol (Address Resolution
Protocol)
ARP Protocol
Manage the ARP Table
(arp Command)
$ arp
$ arp -s <IP Address> <Hardware Address>
$ arp -d <IP Address>
• The arp command is responsible for display and management of the
ARP table
• To Display the ARP Table
$ arp
• To manually add an entry to the ARP Table (normally ARP Table
entries are filled by the ARP Protocol)
$ sudo arp -s 192.168.101.105 00:0C:F1:AC:34:F1
• To manually delete an entry to the ARP Table (normally ARP table
entries expire automatically)
$ sudo arp -d 192.168.101.105
Show the ARP Table
(arp Command)
OK…So How is Routing Done ??
• Now the machine knows the MAC Address of the destination,
and it can deliver the packet to it
Internal IP Addressing and NATing
Why NATing ??
google
yahoo
facebook
cnn
youtube
coursera
Why NATing ??
google
yahoo
facebook
cnn
youtube
coursera
Why NATing ??
google
yahoo
facebook
cnn
youtube
coursera
Why NATing ??
google
yahoo
facebook
cnn
youtube
coursera
192.168.101.7220.16.16.598.10.10.5
98.10.10.5
To:
From: 192.168.101.7:1500
192.168.101.7220.16.16.598.10.10.5
98.10.10.5
To:
From: 220.16.16.5:5000
Public Private
220.16.16.5 5000 192.168.101.7 1500
192.168.101.7220.16.16.598.10.10.5
98.10.10.5
To:
From: 220.16.16.5:5000
Public Private
220.16.16.5 5000 192.168.101.7 1500
192.168.101.7220.16.16.598.10.10.5
Public Private
220.16.16.5 5000 192.168.101.7 1500
192.168.101.7220.16.16.598.10.10.5
From: 98.10.10.5
To:
220.16.16.5:5000
Public Private
220.16.16.5 5000 192.168.101.7 1500
192.168.101.7220.16.16.598.10.10.5
From: 98.10.10.5
To:
220.16.16.5:5000
Public Private
220.16.16.5 5000 192.168.101.7 1500
192.168.101.7220.16.16.598.10.10.5
From: 98.10.10.5
To:
192.168.101.7:1500
Public Private
220.16.16.5 5000 192.168.101.7 1500
192.168.101.7220.16.16.598.10.10.5
From: 98.10.10.5
To:
192.168.101.7:1500
Network Address Translation
• NAT (Network Address Translation) is used to hide internal
network from the rest of the network to,
• Reduce the required number of administered IP Addresses
• Protect the internal network from access from the external
network
• The NAT Router builds a mapping table between the Internal
addresses/ports, and its own address/ports (or from some list
of administered addresses)
• The external network sees only the external addresses
• We only need one globally administered IP address (for the
router)
• The following subnet addresses are reserved for the private
addresses:
Subnet Starting from Ending at
10.0.0.0/8 10.0.0.0 10.255.255.255
172.16.0.0/12 172.16.0.0 172.31.255.255
192.168.0.0/16 192.168.0.0 192.168.255.255
Domain Names
• When accessing a server, it is normally identified by a domain
name instead of IP Address,
• More readable (www.google.com instead of 134.11.234.102)
• Better portability (we can change the server IP Address)
• Enable High Availability (Using a standby server in case of failure)
• Enable Load sharing (Distribution of load among multiple server)
• We need a way to convert the domain name into the IP
Address
• This is achieved through DNS Server
Setting DNS Server Info
(/etc/resolv.conf)
• To set the set of name servers to search for mapping Domain
names to IP Address, edit the file /etc/resolv.conf
• Name servers are specified as follows,
nameserver 208.67.222.222
nameserver 208.67.220.220
• Any changes made to the file will take effect immediately
Machine Hostname Aliases
(/etc/hosts)
• The file /etc/hosts contains a list of aliases to hosts
Resolving Domain Names
(host command)
$ host <Domain Name>
• This command is used to lookup a domain name and return
with its IP Address(es)
• Example:
$ host www.google.com
• Note that the dig command can do a similar job
$ dig www.google.com
http://Linux4EmbeddedSystems.com

More Related Content

PDF
Course 102: Lecture 26: FileSystems in Linux (Part 1)
PDF
Course 102: Lecture 14: Users and Permissions
PDF
Course 102: Lecture 10: Learning About the Shell
PPTX
Introduction 2 linux
PDF
Course 102: Lecture 16: Process Management (Part 2)
PPTX
Linux basic commands
PDF
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
PPT
Basic 50 linus command
Course 102: Lecture 26: FileSystems in Linux (Part 1)
Course 102: Lecture 14: Users and Permissions
Course 102: Lecture 10: Learning About the Shell
Introduction 2 linux
Course 102: Lecture 16: Process Management (Part 2)
Linux basic commands
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Basic 50 linus command

What's hot (20)

PPT
Linux command ppt
PPTX
Linux file system
PDF
Course 102: Lecture 25: Devices and Device Drivers
PDF
Course 102: Lecture 13: Regular Expressions
PDF
An Introduction To Linux
PPTX
Basic commands of linux
PPT
Install and configure linux
PDF
File System Hierarchy
PDF
Linux programming lecture_notes
PDF
Course 102: Lecture 24: Archiving and Compression of Files
PDF
Course 102: Lecture 4: Using Wild Cards
PDF
50 most frequently used unix linux commands (with examples)
PDF
Course 102: Lecture 18: Process Life Cycle
PPT
Linux file system
PPT
Shell and its types in LINUX
PPTX
Introduction to Linux
PDF
netfilter and iptables
PDF
Course 101: Lecture 5: Linux & GNU
PPTX
Linux User Management
PDF
Course 102: Lecture 2: Unwrapping Linux
Linux command ppt
Linux file system
Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 13: Regular Expressions
An Introduction To Linux
Basic commands of linux
Install and configure linux
File System Hierarchy
Linux programming lecture_notes
Course 102: Lecture 24: Archiving and Compression of Files
Course 102: Lecture 4: Using Wild Cards
50 most frequently used unix linux commands (with examples)
Course 102: Lecture 18: Process Life Cycle
Linux file system
Shell and its types in LINUX
Introduction to Linux
netfilter and iptables
Course 101: Lecture 5: Linux & GNU
Linux User Management
Course 102: Lecture 2: Unwrapping Linux
Ad

Viewers also liked (20)

PDF
C 102 lec_29_what_s_next
PPTX
The TCP/IP Stack in the Linux Kernel
PPT
Data Communication and Computer Networking Part # 1
PDF
Dns On Linux
PDF
Course 102: Lecture 28: Virtual FileSystems
PPTX
CCNA_Data Communication and Computer Networking
PDF
DATA COMMUNICATION AND NETWORKING
PDF
Managing effective communication network in organisation through diplomacy
PDF
Course 102: Lecture 22: Package Management
PDF
Embedded Systems: Lecture 4: Selecting the Proper RTOS
PDF
Embedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi AP
PDF
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
PDF
Embedded Systems: Lecture 7: Lab 1: Preparing the Raspberry Pi
PDF
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
PDF
Course 102: Lecture 27: FileSystems in Linux (Part 2)
PDF
Course 102: Lecture 9: Input Output Internals
PDF
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
PDF
Embedded Systems: Lecture 1: Course Overview
PDF
Embedded Systems: Lecture 7: Unwrapping the Raspberry Pi
PDF
Course 102: Lecture 8: Composite Commands
C 102 lec_29_what_s_next
The TCP/IP Stack in the Linux Kernel
Data Communication and Computer Networking Part # 1
Dns On Linux
Course 102: Lecture 28: Virtual FileSystems
CCNA_Data Communication and Computer Networking
DATA COMMUNICATION AND NETWORKING
Managing effective communication network in organisation through diplomacy
Course 102: Lecture 22: Package Management
Embedded Systems: Lecture 4: Selecting the Proper RTOS
Embedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi AP
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 7: Lab 1: Preparing the Raspberry Pi
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Course 102: Lecture 27: FileSystems in Linux (Part 2)
Course 102: Lecture 9: Input Output Internals
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Embedded Systems: Lecture 1: Course Overview
Embedded Systems: Lecture 7: Unwrapping the Raspberry Pi
Course 102: Lecture 8: Composite Commands
Ad

Similar to Course 102: Lecture 20: Networking In Linux (Basic Concepts) (20)

PPT
Networking Chapter 7
PPTX
Topic 2.3 network addressing for tcpip
PDF
Network Programming Assignment Help
PPTX
Microsoft Offical Course 20410C_05
PPT
Addressing
PPTX
09 Systems Software Programming-Network Programming.pptx
PPT
Subnetting
PPT
Ipaddress presentationdemoclass
PPTX
4. Understanding Internet Protocol.pptx
PPTX
PPT
How IP address works
PPTX
Computer network coe351- part3-final
PDF
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
PDF
Networking Brush Up for Amazon AWS Administrators
PPT
chsadsadasdasdasdasdsadsadsadsadsadasda10.ppt
PPTX
Addressing in networking (IP,MAC,Port addressing)
PPTX
CCNA IP Address Presentation(Part 1)
PPT
IPv6 networking training sduffy v3
PPTX
70-410_r2_lecture_slides_lehjhjkhjkhjhkjhjkhkjsson_10.pptx
PPTX
Configuring IPv4 and IPv6 Addressing to STEM
Networking Chapter 7
Topic 2.3 network addressing for tcpip
Network Programming Assignment Help
Microsoft Offical Course 20410C_05
Addressing
09 Systems Software Programming-Network Programming.pptx
Subnetting
Ipaddress presentationdemoclass
4. Understanding Internet Protocol.pptx
How IP address works
Computer network coe351- part3-final
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Networking Brush Up for Amazon AWS Administrators
chsadsadasdasdasdasdsadsadsadsadsadasda10.ppt
Addressing in networking (IP,MAC,Port addressing)
CCNA IP Address Presentation(Part 1)
IPv6 networking training sduffy v3
70-410_r2_lecture_slides_lehjhjkhjkhjhkjhjkhkjsson_10.pptx
Configuring IPv4 and IPv6 Addressing to STEM

More from Ahmed El-Arabawy (13)

PDF
Course 102: Lecture 19: Using Signals
PDF
Course 102: Lecture 17: Process Monitoring
PDF
Course 102: Lecture 12: Basic Text Handling
PDF
Course 102: Lecture 11: Environment Variables
PDF
Course 102: Lecture 7: Simple Utilities
PDF
Course 102: Lecture 6: Seeking Help
PDF
Course 102: Lecture 5: File Handling Internals
PDF
Course 102: Lecture 3: Basic Concepts And Commands
PDF
Course 102: Lecture 1: Course Overview
PDF
Course 101: Lecture 6: Installing Ubuntu
PDF
Course 101: Lecture 4: A Tour in RTOS Land
PDF
Course 101: Lecture 2: Introduction to Operating Systems
PDF
Course 101: Lecture 1: Introduction to Embedded Systems
Course 102: Lecture 19: Using Signals
Course 102: Lecture 17: Process Monitoring
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 11: Environment Variables
Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 6: Seeking Help
Course 102: Lecture 5: File Handling Internals
Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 1: Course Overview
Course 101: Lecture 6: Installing Ubuntu
Course 101: Lecture 4: A Tour in RTOS Land
Course 101: Lecture 2: Introduction to Operating Systems
Course 101: Lecture 1: Introduction to Embedded Systems

Recently uploaded (20)

PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
cuic standard and advanced reporting.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
A Presentation on Artificial Intelligence
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation theory and applications.pdf
NewMind AI Weekly Chronicles - August'25 Week I
cuic standard and advanced reporting.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
NewMind AI Monthly Chronicles - July 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Review of recent advances in non-invasive hemoglobin estimation
A Presentation on Artificial Intelligence
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
Dropbox Q2 2025 Financial Results & Investor Presentation

Course 102: Lecture 20: Networking In Linux (Basic Concepts)

  • 1. Linux For Embedded Systems ForArabs Ahmed ElArabawy Course 102: UnderstandingLinux
  • 2. Lecture 20: Networking in Linux (Basic Concepts)
  • 3. Why Networking ?? • Networking is a very essential tool for Linux Users/developers • Setup our machine to be able to connect to the internet • Identify our machine information (interfaces/IP Address/ …) • Copy files to/from remote machines • Copy files to/from the web • Remotely access a remote machine • And Other important tasks….
  • 4. Why Networking ?? • For an embedded developer, networking is even much more essential • Embedded Systems normally comes without a display, and we will need to connect to it via a host machine • We will need to connect to the embedded target for: • Reading the logs • Debugging the program • Setting some configuration files • Uploading a new image
  • 5. So …. • Networking to an embedded user/developer aims for two main purposes • Connect to a remote machine or to the internet • This is typically done using an Ethernet connection • Connect a host machine to the embedded target • This can be achieved via, • JTAG Connection • Serial Console Connection • Ethernet Connection
  • 7. Network Interfaces • The computer/board may have one or more network interfaces • In Hardware, this is represented by, • An Ethernet NIC card • WiFi port • In Linux, each interface will have a name, • Examples (eth0, eth1, …. )
  • 8. Showing the Network Interfaces (ifconfig Command) $ ifconfig $ ifconfig <interface name> [up/down] • This command is responsible for showing and managing interfaces • To show the interfaces in the system $ ifconfig $ ifconfig -s (shows an abstract description) • To show info about a specific interface $ ifconfig eth1 • To activate/deactivate $ ifconfig eth1 up $ ifconfig eth2 down
  • 9. Showing the Network Interfaces (ifconfig Command)
  • 10. The MAC Address • The MAC address is also called the Hardware Address • It is a unique address for each NIC card (set by the manufacturer) • It is a 48 bit number written in hexadecimal format (4 bit digits) as follows, 68:05:CA:03:19:9C • Note, • Hexadecimal format is a format that converts every 4 bits into a single digit • Since 4 bits require 16 combinations (takes values from 0 – 15), the digits (0-9, A,B,C,D,E,F) are used • Accordingly, since the MAC address is 48 bits, it will be written in 12 hexadecimal digits
  • 12. MAC Address 00:0C:F1:AC:34:F1 Manufacturer = Intel 0000:0000 Unicast Address Globally Unique
  • 14. Local Area Network • A Local Area Network (LAN) is a set of computers connected together via hub/switch • The devices (computers) are located in the same area (locally located) • The computers have the same type of network interface (Ethernet, Wifi, …) • Data is transferred between the machines based on their MAC addresses
  • 16. A Real Network • In a more realistic network, not all computer reside in the same LAN, • Limitation on distance between the devices • Different kind of requirements (Wired/wireless/…) • Need to isolated devices in groups • Other… • Hence A typical network is composed of a group of LANs interconnected with each other with some routing devices • Within each LAN, MAC address is used for communication inside this LAN • However, the MAC Address is no longer enough to communicate between the devices in different LANs, and we need a more global addressing scheme • This is called network addressing which uses the IP Address
  • 17. IP Address • Any network interface on a machine in the network is identified by its IP Address • Sometimes the interface may have multiple IP-Addresses • The IP address is composed of 4 numbers (0-255) separated by a dot • Example: 192.168.101.112 • This is assuming, we are using IPv4, another version which is IPv6 has a different format • Note that the number 0-255 is an 8 bit number
  • 19. Is IP Address Enough ?? • Port numbers identify different services within the same IP Address • Each connection will have both source port and destination port numbers
  • 21. Subnet • To Facilitate Routing, • The machines are organized into small networks (subnets) • Subnets share the upper part of the IP address 132.201.1.100 132.201.1.101 132.201.1.102 132.201.1.103 132.201.1.104 132.201.2.100 132.201.2.101 132.201.2.103 132.201.2.102 132.201.2.104 132.201.3.100 132.201.3.101 132.201.3.102 132.201.3.103 132.201.3.104
  • 23. Subnet • Network interfaces within the same subnet share the upper part of the IP address, and differ in the lower part • The number of bits shared within the subnet control the subnet size • For example if we have the upper 24 bits (3 bytes) shared within the subnet, then the interfaces with the subnet can differ in 8 bits only, which leads to a maximum of 256 addresses • If the shared part is reduced to 20 bits only, we will have 12 bits to change which lead to 4096 different addresses • The part of the IP Address shared among the interfaces within the subnet, is expressed as the subnet mask
  • 25. Subnet Mask 192.168.101.112 11000000 10101000 01100101 01110000 Subnet Address : 192.168.101.0 Subnet Mask : 255.255.255.0 Address : 192.168.101.112/24
  • 26. Subnet Mask 192.168.101.112 11000000 10101000 01100101 01110000 Subnet Address : 192.168.96.0 Subnet Mask : 255.255.240.0 Address : 192.168.101.112/19
  • 27. Subnet Mask Subnet Mask: 255.255.255.0 Subnet Mask: 255.255.255.0 Subnet Mask: 255.255.255.0
  • 29. Show Subnet Mask (ifconfig Command) $ ifconfig
  • 30. IP Address Allocation • IP Address can be allocated in two different ways, • Statically allocated • This is done manually, or via a startup script • Address is always the same • Dynamically allocated via a DHCP server • At startup, the machine asks a DHCP server to provide it with an IP Address • The DHCP server responds with an unused IP address within the proper subnet • Hence, the IP address can change every time the machine boots • The DHCP server can be configured so it will always assign a specific machine the same IP Address • Using DHCP address allocation is more convenient and more flexible • Since the DHCP server needs to be accessed before the IP address is allocated, it should reside within the same LAN as the machines (it is typically located inside the LAN switch)
  • 31. Allocating IP Address (ifconfig Command) $ ifconfig <interface> <IP Address> $ ifconfig <interface> <IP Address> netmask <netmask> $ ifconfig <interface> netmask <netmask> Used to statically allocate IP address to an Interface and/or set its net-mask • Example: $ ifconfig eth1 192.268.0.10 $ ifconfig eth1 netmask 255.255.255.224 $ ifconfig eth1 192.268.0.10 netmask 255.255.255.224
  • 32. Special IP Addresses • Some IP Addresses have a special meaning, • The Address 127.0.0.1 is reserved for the Local Host. This means it is used as a loop back address • Any address ending with all ones (after the subnet mask), is a broadcast address within this subnet • Example, In the Subnet 192.168.224.0/19 the broadcast address would be, 192.168.255.255 • Any address of the format xxx.xxx.xxx.1 is reserved for the default gateway • The following subnets are reserved for private addressing (to be discussed later) Subnet Starting from Ending at 10.0.0.0/8 10.0.0.0 10.255.255.255 172.16.0.0/12 172.16.0.0 172.31.255.255 192.168.0.0/16 192.168.0.0 192.168.255.255
  • 33. OK…So How is Routing Done ??
  • 34. OK…So How is Routing Done ??
  • 35. OK…So How is Routing Done ?? • First the destination address is checked to be within the same subnet of the sender or not • If it is on the same subnet, • Then delivering the packet will need to be done based on the MAC address • This means we will need to know the MAC address of the destination • We will not need this now, since the destination address does not belong to the sender subnet • If it is not on the same subnet, • Then we will need to deliver the packet to the proper next hop • The next hop is identified based on the Routing Table • The routing table is a table of routes that identifies the next hop based on the packet destination
  • 36. OK…So How is Routing Done ??
  • 37. Show the Routing Table (route Command) $ route • The route command shows the entries of the routing table $ route • Each route contains, • Destination: This is an address, whether a host address or a subnet address • Network mask: Used when a subnet address is used for destination • Interface: The used interface for this destination • Gateway: The next hop for this destination • Upon the reception of a packet, • Linux tests the packet destination address to match the destination of the routes • If a match exists, Linux forwards the packet to the defined interface, towards the specified GW address
  • 38. Show the Routing Table (route Command)
  • 39. Manage Routing Table (route command) $ route add <address> dev <interface> gw <address> $ route add default gw <address> $ route del <address> $ route del default • To add a route $ sudo route add 192.56.76.123 dev eth1 gw 192.168.101.1 $ sudo route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0 $ sudo route add default gw 192.168.101.1 • To delete a route $ sudo route del default $ sudo route del 192.168.100.20
  • 40. OK…So How is Routing Done ??
  • 41. OK…So how is Routing Done ?? • Now the router has received the packet • It should also check its routing table to identify the proper interface to use for forwarding the packet • The destination is found to belong to the subnet 141.14.2.0/24, and the interface is identified • Now we need to deliver the packet to its destination within the subnet • Since delivering the packet within the subnet is based on the MAC Address, we will need to know the MAC address of the destination What is the MAC Address for the Host 141.14.2.105 ???
  • 42. Identifying the MAC Address … (The ARP Protocol) • The machine should have a table that maps IP Addresses to MAC addresses within its subnet • This table is called the ARP table • If the machine does not have the address in its table, it queries it using the ARP protocol (Address Resolution Protocol)
  • 44. Manage the ARP Table (arp Command) $ arp $ arp -s <IP Address> <Hardware Address> $ arp -d <IP Address> • The arp command is responsible for display and management of the ARP table • To Display the ARP Table $ arp • To manually add an entry to the ARP Table (normally ARP Table entries are filled by the ARP Protocol) $ sudo arp -s 192.168.101.105 00:0C:F1:AC:34:F1 • To manually delete an entry to the ARP Table (normally ARP table entries expire automatically) $ sudo arp -d 192.168.101.105
  • 45. Show the ARP Table (arp Command)
  • 46. OK…So How is Routing Done ?? • Now the machine knows the MAC Address of the destination, and it can deliver the packet to it
  • 54. 98.10.10.5 To: From: 220.16.16.5:5000 Public Private 220.16.16.5 5000 192.168.101.7 1500 192.168.101.7220.16.16.598.10.10.5
  • 55. 98.10.10.5 To: From: 220.16.16.5:5000 Public Private 220.16.16.5 5000 192.168.101.7 1500 192.168.101.7220.16.16.598.10.10.5
  • 56. Public Private 220.16.16.5 5000 192.168.101.7 1500 192.168.101.7220.16.16.598.10.10.5 From: 98.10.10.5 To: 220.16.16.5:5000
  • 57. Public Private 220.16.16.5 5000 192.168.101.7 1500 192.168.101.7220.16.16.598.10.10.5 From: 98.10.10.5 To: 220.16.16.5:5000
  • 58. Public Private 220.16.16.5 5000 192.168.101.7 1500 192.168.101.7220.16.16.598.10.10.5 From: 98.10.10.5 To: 192.168.101.7:1500
  • 59. Public Private 220.16.16.5 5000 192.168.101.7 1500 192.168.101.7220.16.16.598.10.10.5 From: 98.10.10.5 To: 192.168.101.7:1500
  • 60. Network Address Translation • NAT (Network Address Translation) is used to hide internal network from the rest of the network to, • Reduce the required number of administered IP Addresses • Protect the internal network from access from the external network • The NAT Router builds a mapping table between the Internal addresses/ports, and its own address/ports (or from some list of administered addresses) • The external network sees only the external addresses • We only need one globally administered IP address (for the router) • The following subnet addresses are reserved for the private addresses: Subnet Starting from Ending at 10.0.0.0/8 10.0.0.0 10.255.255.255 172.16.0.0/12 172.16.0.0 172.31.255.255 192.168.0.0/16 192.168.0.0 192.168.255.255
  • 61. Domain Names • When accessing a server, it is normally identified by a domain name instead of IP Address, • More readable (www.google.com instead of 134.11.234.102) • Better portability (we can change the server IP Address) • Enable High Availability (Using a standby server in case of failure) • Enable Load sharing (Distribution of load among multiple server) • We need a way to convert the domain name into the IP Address • This is achieved through DNS Server
  • 62. Setting DNS Server Info (/etc/resolv.conf) • To set the set of name servers to search for mapping Domain names to IP Address, edit the file /etc/resolv.conf • Name servers are specified as follows, nameserver 208.67.222.222 nameserver 208.67.220.220 • Any changes made to the file will take effect immediately
  • 63. Machine Hostname Aliases (/etc/hosts) • The file /etc/hosts contains a list of aliases to hosts
  • 64. Resolving Domain Names (host command) $ host <Domain Name> • This command is used to lookup a domain name and return with its IP Address(es) • Example: $ host www.google.com • Note that the dig command can do a similar job $ dig www.google.com