DHCP Nat
DHCP Nat
DHCP Nat
DHCP –
Dynamic Host Configuration Protocol
Computer Center, CS, NCTU
DHCP Motivation
BOOTP
• Support sending extra information beyond an IP address to a client to
enable customized configuration
• Effectively solve one of the major problems that administrators have
with manual configuration
Problems of BOOTP
• BOOTP normally uses a static method of determining what IP address
to assign to a device
3
Computer Center, CS, NCTU
DHCP introduction
DHCP
• Dynamic address assignment
A pool of IP address is used to dynamically allocate addresses
Still support static mapping of addresses
• Enable a DHCP client to “lease” a variety of network parameters
IP, netmask
Default router, DNS servers
A system can connect to a network and obtain the necessary information dynamically
Client-Server architecture
• DHCP client broadcasts request for configuration info.
UDP port 68
• DHCP server reply on UDP port 67, including
IP, netmask, DNS, router, IP lease time, etc.
RFC
• RFC 2131 – Dynamic Host Configuration Protocol
• RFC 2132 – DHCP Options
Two main function of DHCP
• Provide a mechanism for assigning addresses
• A method by which clients can request addresses and other configurations
4
Computer Center, CS, NCTU
DHCP Address Assignment
5
Computer Center, CS, NCTU
Dynamic allocation
6
Computer Center, CS, NCTU
DHCP Leases
7
Computer Center, CS, NCTU
DHCP Lease “Life Cycle”
Life cycle
• Allocation
• Reallocation
• Normal operation
• Renewal
• Rebinding
• Release
8
Computer Center, CS, NCTU
DHCP Lease Address Pools
9
Computer Center, CS, NCTU
DHCP Protocol (1)
client server
DHCP Discover 廣播:
• Broadcasted by client to find available 我 要 IP
server. DHCP Discover
src: 0.0.0.0 port: 68
• Client can request its last-known IP, but the dst: 255.255.255.255 port: 67
10
Computer Center, CS, NCTU
DHCP Protocol (2)
DHCP inform
• Request more information than the server sent.
• Repeat data for a particular application.
ex. browsers request web proxy settings from server.
• It does not refresh the IP expiry time in server’s database.
DHCP Release
• Client send this request to server to releases the IP, and the client
will un-configure this IP.
• Not mandatory.
11
Computer Center, CS, NCTU
DHCP server on FreeBSD (1)
Kernel support
device bpf (FreeBSD 5.x↑)
pseudo-device bpf (FreeBSD 4.x↓)
Install DHCP server
• /usr/ports/net/isc-dhcp41-server/
• % cd /usr/local/etc
• % cp dhcpd.conf.sample dhcpd.conf
Enable DHCP server in /etc/rc.conf
dhcpd_enable="YES“
dhcpd_flags="-q“
dhcpd_conf="/usr/local/etc/dhcpd.conf“
dhcpd_ifaces="“
dhcpd_withumask="022"
12
Computer Center, CS, NCTU
DHCP server on FreeBSD (2)
Option definitions
option domain-name "cs.nctu.edu.tw";
option domain-name-servers 140.113.235.107, 140.113.1.1;
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
log-facility local7;
/etc/syslogd.conf
/etc/newsyslog.conf
13
Computer Center, CS, NCTU
DHCP server on FreeBSD (3)
Subnet definition
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.101 192.168.1.200;
option domain-name "cs.nctu.edu.tw";
option routers 192.168.1.254;
option broadcast-address 192.168.1.255;
option domain-name-servers 140.113.17.5, 140.113.1.1;
default-lease-time 3600;
max-lease-time 21600;
}
Host definition
host fantasia {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address 192.168.1.30;
}
host denyClient {
hardware ethernet 00:07:95:fd:12:13;
deny booting;
}
14
Computer Center, CS, NCTU
DHCP server on FreeBSD (4)
Important files
• /usr/local/sbin/dhcpd
• /usr/local/etc/dhcpd.conf
• /var/db/dhcpd.leases (leases issued)
• /usr/local/etc/rc.d/isc-dhcpd
15
NAT –
Network Address Translation
Computer Center, CS, NCTU
IP address crisis
IP address crisis
• Run out of class B address
The most desirable ones for moderately large organizations
• IP address were being allocated on a FCFS
With no locality of reference
Solutions
• Short term
Subnetting and CIDR (classless inter-domain routing)
NAT (network address translation)
• Long term
IPv6
17
Computer Center, CS, NCTU
Network Address Translation (NAT)
18
Computer Center, CS, NCTU
Private Address Space
Operation consideration
• Router should set up filters for both inbound and outbound private network
traffic
19
Computer Center, CS, NCTU
Network Address Translation (NAT)
What is NAT?
• Network Address Translation
• Re-write the source and/or destination addresses of IP packets when they
pass through a router or firewall.
• What can be re-written?
Source/destination IPs
Source/destination ports
What can NAT do?
• Solve the IPv4 address shortage. (the most common purpose)
• Kind of firewall (security)
• Load balancing
• Fail over (for service requiring high availability)
20
NAT Terminology
Computer Center, CS, NCTU
21
Computer Center, CS, NCTU
NAT Address Mappings
Translation table
• Maps the inside local address to the inside global address
• Also contains mappings between outside global address and outside local
address for inbound translations
22
Computer Center, CS, NCTU
NAT Unidirectional Operation
23
Computer Center, CS, NCTU
NAT Bidirectional Operation
24
Computer Center, CS, NCTU
NAT Bidirectional Operation
25
Computer Center, CS, NCTU
NAT Bidirectional Operation
26
Computer Center, CS, NCTU
NAT Port-Based Operation
27
Computer Center, CS, NCTU
NAT Port-Based Operation
28
Computer Center, CS, NCTU
NAT Port-Based Operation
NAT example:
29
Computer Center, CS, NCTU
NAT Overlapping Operation
30
Computer Center, CS, NCTU
NAT Overlapping Operation
31
Computer Center, CS, NCTU
NAT Compatibility Issues
32
Computer Center, CS, NCTU
SNAT
S: 192.168.1.1:1234 S: 140.113.235.250:10234
D: 140.113.235.107:53 D: 140.113.235.107:53
192.168.1.254 140.113.235.250
192.168.1.1 140.113.235.250
NAT Mapping Table:
192.168.1.1:1234 – 140.113.235.250:10234
33
Computer Center, CS, NCTU
DNAT
• DNAT
Rewrite the destination IP and/or Port.
The rewritten packet will be redirect to another IP address when
it pass through NAT server.
S: 140.113.24.107:1357 S: 140.113.24.107:1357
D: 192.168.1.1:80 D: 140.113.235.107:8080
192.168.1.254 140.113.235.250
192.168.1.1 140.113.24.107
NAT Mapping Table:
140.113.235.250:8080 – 192.168.1.1:80
34
Computer Center, CS, NCTU
NAT on FreeBSD (1)
Setup
• Network topology
• configuration
• Advanced redirection
configuration
192.168.1.1
Web server
192.168.1.2
Ftp Server
192.168.1.101
PC1
35
Computer Center, CS, NCTU
NAT on FreeBSD (2)
Enable NAT
• Here we use Packet Filter (PF) as our NAT server
• Configuration file: /etc/pf.conf
nat # macro definitions
rdr extdev='fxp0‘
binat intranet='192.168.1.0/24‘
webserver=‘192.168.1.1’
ftpserver=‘192.168.1.2’
pc1=‘192.168.1.101’
# nat rules
nat on $extdev inet from $intranet to any -> $extdev
rdr on $extdev inet proto tcp to port 80 -> $webserver port 80
rdr on $extdev inet proto tcp to port 443 -> $webserver port 443
36 rdr on $extdev inet proto tcp to port 21 -> $ftpserver port 21
Computer Center, CS, NCTU
NAT on FreeBSD (3)
# macro definitions
extdev='fxp0‘
intranet='192.168.219.0/24‘
winxp=‘192.168.219.1’
server_int=‘192.168.219.2’
server_ext=‘140.113.214.13’
# nat rules
nat on $extdev inet from $intranet to any -> $extdev
rdr on $extdev inet proto tcp to port 3389 -> $winxp port 3389
binat on $extdev inet from $server_int to any -> $server_ext
37