Sunteți pe pagina 1din 35

-

C h a pte r 11 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g

p ra ctice i s c o m m o n i n syst e m s host i n g se rvices f o r m u l t i p l e c l i e nts, s u c h a s HTTP I P-based


host i n g . Red H a t Enterprise Linux i nte rfa ces ty pica l l y have a n 1 Pv4 a d d ress a n d a n 1 Pv 6 l o ca l - l i n k
-
a d d ress, b u t m a y have m o re a d d resses a s s i g n e d .

Network interface names -


Tra d i t i o n a l l y, n etwo r k i nterfaces in L i n u x a re e n u m e rated as e t h0, e t h 1 , e t h2, and so o n .
H owever, t h e mecha n i s m w h i c h sets t h ese n a m es ca n c a u s e c h a n g es to w h i c h i nterface gets
w h i c h name a s devices a re a d d e d and removed. T h e defa u lt n a m i n g behavior i n Red Hat -

E nterprise L i n u x 7 is to a s s i g n fixed n a mes based o n f i r mwa re, d evice topol ogy, and device type.
I nt e rface n a m es have t h e fo l l owi n g c h a ra cters:

• Et h e r n et i nte rfa ces beg i n with en, W L A N i nterfaces b eg i n with w/, and WWAN i nt e rfaces b eg i n
w i t h WW.
-
• T h e next c h a racte r(s) represents t h e type of a d a pt e r w i t h a n o for on-board, s for h ot p l u g s l ot,
and p for P C I geo gra p h i c l o c a t i o n . Not used by defa u l t b u t also avai l a b l e to a d m i n istrators, a n x
is u sed to i n co r p o rate a M A C a d d ress.

• F i n a l l y, a n u m be r N i s used to re p resent a n i n d ex, I D, o r po rt.


-
• I f the fixed name ca n n ot b e d ete r m i n ed , the t ra d i t i o n a l n a m es such a s ethN w i l l b e u s e d .

Fo r exa m p l e, t h e fi rst e m b e d d e d n e t w o r k i n terfa ce m a y be n a m e d eno1 a n d a P C I c a rd n etwork


i nterface m a y be named enp2s0. T h e new names m a ke it easier to d i st i n g u i s h t h e re l a t i o n s h i p
betwee n a p o r t a n d i t s n a m e if t h e u s e r k n ows bot h , b u t t h e t ra d e off is t h a t u s e rs ca n n ot
a s s u m e a system with o n e i nte rface ca l l s that i nte rfa ce e t h0.
-

Note
-
Network i nterface n a m i n g ca n be ove r r i d d e n . I f t h e a d m i n istrator h a s i n sta l l e d a n d
e n a b l ed t h e biosdevname package o r set customized u d ev device n a m i n g r u l es,
t hose sett i n g s w i l l ove r r i d e t h e defa u lt n a m i n g s c h e m e. D e p e n d i n g o n s u p p o rt for -
biosdevname in t h e system B I OS, n a m es such a s em1, em2, etc. may b e used for o n ­
b o a rd n e t w o r k cards (corres p o n d i n g to t h e i r n a m es o n t h e c hassis). PC l (e) cards a re
represented w i t h p YpX (e.g., p4p1), w h e re Y i s t h e P C I s l ot n u m be r a n d X is t h e n u m be r
f o r t h e port on t h a t specific c a rd .

R References
se rvices(5), ping(8), biosdevname(1 ), a n d u d ev(7) m a n pages -

A d d i t i o n a l i n fo r m a t i o n m a y b e a va i l a b l e i n t h e c h a pters o n config u ri n g n etwo r k i n g a n d


co n s i stent n etwo r k d evice n a m i n g i n t h e Red Hat Enterprise Linux Networking Guide
for Red H a t Enterprise L i n u x 7, w h i c h ca n be fou n d a t
http://d ocs.red hat.com/
-

262 RH124- R H E L7-en-1 -20140606

-
-

Practice: N etwo r k i n g C o n cepts

P ra ct i ce: N etwo r k i n g Concepts


-

Quiz

Match t h e fo l l ow i n g items to t h e i r cou nterpa rts i n the t a b l e.

Gateway i s not o n t h e s a m e s u b n et.

I P a d d ress ca n n ot be a n etwo r k a d d ress. I nva l i d 1 Pv4 a d d ress

-
N a m e reso l ut i o n i s not c o n f i g u re d . T h i s confi g u ra t i o n i s fea s i b le.

N etwork settin g s Correctn ess

IP address :
-- -
-�- - ------ - - - -

172 . 17 . 0 . 351/16
Gateway : 172 . 17 . 0 . 1
-

-
DNS server : 172 . 17 . 0 . 254 '

-- -- -

IP address : 10 . 1 . 2 . 3/24
- -

Gateway : 10 . 1 . 2 . 1
i

DNS server : 172 . 17 . 4 . 53


i
'
-

'

� -

IP address : 192 . 168 . 7 . 0/24


Gateway : 192 . 168 . 7 . 1
'

DNS server : 192 . 168 . 0 . 254


-

-- - �

IP address : 10 . 4 . 5 . 6/24
-- - - - - -

Gateway : 10 . 4 . 6 . 1
-

DNS server : 192 . 168 . 0 . 254


!
;

-
'- - ----- - -- -

- R H 1 24- R H E L 7-en-1 -20140606 263

-
C h a pter 1 1 . M a n a g i n g Red H a t Enterprise L i n u x Networking
-

N etwo r k sett i n g s C o r re ct n ess

IP address : 172 . 17 . 23 . 5/16


Gateway : 172 . 17 . 0 . 1

264 R H1 24- R H E L7 - e n -1 -20140606


-

Sol ution
-

Solution
-

Match t h e fo l l ow i n g items to t h e i r cou nterpa rts i n t h e ta b l e.

N etwork settin g s Correctn ess

IP address :
--��
I nva l i d 1 Pv4 a d d ress
: 172 . 17 . 0 . 351/16
--� -- - --- - - - ---

i Gateway : 172 . 17 . 8 . 1
i DNS server : 172 . 17 . 0 . 254
-

IP address : 10 . 1 . 2 . 3/24
.---- --��- -�-���1 T h i s confi g u ra t i o n i s feas i b l e.
Gateway : 10 . 1 . 2 . 1
-

-
DNS server : 172 . 17 . 4 . 53

IP address : 192 . 168 . 7 . 0/24 1


-
- - ---- - -- -- -�-�
-��-c
I P a d d ress ca n n ot be a netwo rk a d d ress.
Gateway : 192 . 168 . 7 . 1
-

DNS server : 192 . 168 . 0 . 254


� --- �--- -- --- -

IP address : 10 . 4 . 5 . 6/24
Gateway i s n ot o n the same s u b n et.
Gateway : 10 . 4 . 6 . 1
-- - -- - - - --��

I
DNS server : 192 . 168 . 0 . 254 I

; IP address : 172 . 17 . 23 . 5/16 j


N a m e reso l ut i o n i s not conf i g u re d .
, Gateway : 172 . 17 . 0 . 1
-

- R H 1 24- R H E L 7-en-1 -20140606 265

-
-

C h a pt e r 1 1 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g

Va l id at i n g N etwo rk Confi g u rat i o n


-

Objectives
Afte r com p l e t i n g t h i s sect i o n , students s h o u l d be a b l e to test a n d rev iew c u rrent n etwork
confi g u ra t i o n w i t h basic u t i l i t i es.

Displaying I P ad dresses
T h e / s bin/ip com m a n d is u sed to s h ow device a n d a d d ress i nfo r m a t i o n .

[ student@desktopX -] $ ip addr show eth0


-
�-

I
2 : eth0 : <BROADCAST, MULTICAST, C» uP, LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen
1000
-

«) link/ether 52 : 54 : 00 : 00 : 00 : 0a brd ff : ff : ff : ff : ff : ff
E> inet 172 . 25 . 0 . 10/24 brd C» 112 . 25 . 0 . 255 scope global eth0
valid_lft forever preferred_lft forever
-

C) inet6 fe80 : : 5054 : ff : fe00 : b/64 scope link


valid_lft forever preferred_lft forever
C» An active i nterface h a s t h e stat u s of UP.
f) The l i n k l i n e specifies t h e ha rdwa re ( M AC) a d d ress of t h e device.
E> The i n et l i n e s h ows t h e 1 Pv4 a d d ress a n d p refi x .
C) The broadcast a d d ress, scope, a n d device n a m e a re a l so o n t h i s l i ne. -

C) The i n et6 l i n e s hows 1 Pv6 info r m a t i o n .

T h e ip com m a n d may a l s o b e used to s h ow statistics a bo u t n e t w o r k p e rfo r m a n ce. T h e received


(RX) and t ra n s m itted (TX) p a c kets, e r rors, and d ro p p e d cou n t e rs can be used to ident ify n etwo r k
i s s u e s caused b y co n g e st i o n , l ow m e m o ry, a n d ove r r u n s.

[student@desktopX -]$ ip - s link show ethe


2 : eth0 : <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52 : 54 : 00 : 00 : 00 : 0a brd ff : ff : ff : ff : ff : ff
RX : bytes packets errors dropped overrun mcast
269850 2931 0 0 0 0
TX : bytes packets errors dropped carrier collsns
300556 3250 0 0 0 0 -

Troubleshooting routing -

T h e /sbin/ip com m a n d is a l so u s e d to s how ro u t i n g i n fo r m a t i o n .

[student@desktopX -]$ ip route


default via 172 . 25 . 0 . 254 dev eth0 proto static met ric 1024
172 . 25 .X. 0/24 dev eth0 proto kernel scope link src 172 . 25 .X. 10
10 . 0 . 0 . 0/8 dev eth1 proto kernel scope link src 10 . 0 . 0 . 11
A l l packets dest i n e d for t h e 1 0.0.0.0/8 network w i l l be sent d i re c t l y to t h e dest i n a t i o n t h ro u g h
-
t h e device eth1 . A l l pac kets d e st i n ed f o r t h e 172.25.X.0/24 n etwork wi l l be s e n t d i rect l y to t h e
dest i n a t i o n t h ro u g h t h e d e v i c e e t h O . A l l o t h e r pac kets w i l l b e s e n t to t h e defa u l t ro u t e r l ocated a t
172.25.X.254, a n d a l s o t h ro u g h device ethO.

266 R H 1 24- R H E L 7 - e n -1 -20140606 -

-
-

Tro u b l es h o o t i n g ports a n d services


-
The ping co m m a n d is used to test c o n n ectivity. The co m m a n d w i l l cont i n u e to r u n until a

I [student@desktopX
Con t r ol - C i s p ressed u n less o p t i o n s a re g i v e n to l i m it t h e n u m be r of p a c kets sent.
-

- ) $ ping - c3 172 . 25 . X . 254


I
-
To t race t h e path to a remote host, u s e e i t h e r t r ace rou t e or t r acepath. Both com m a n d s ca n
be used to t race a path with U D P p a c kets; h owever, m a ny networks b l oc k U D P a n d I C M P t raffic.
- The t r ace route co m m a n d h a s options to t race t h e path w i t h UDP (defa u lt), I C M P ( I ) o r TC P -
,

( - T) p a c kets, but m a y not be i n sta l l e d by defa u lt .

- [student@desktopX - ) $ t racepat h access . redhat . com


4 : 71-32-28-145 . rcmt . qwest . net 48 . 853ms asymm 5
5 : dcp- brdr -04 . inet . qwest . net 100 . 732ms asymm 7
6 : 206 . 111 . 0 . 153 . ptr . us . xo . net 96 . 245ms asymm 7
7 : 207 . 88 . 14 . 162 . ptr . us . xo . net
-

85 . 270ms asymm 8
8 : ae1d0 . cir1 . atlanta6-ga . us . xo . net 64 . 160ms asymm 7
9 : 216 . 156 . 108 . 98 . ptr . us . xo . net 108 . 652ms
10 : bu-ether13 . atlngamq46w- bcr00 . tbone . rr . com 107 . 286ms asymm 12
-

-
Each l i n e in the o u t p u t of t r acepat h re presents a ro uter o r hop that the pac ket passes t h ro u g h
betwe e n t h e s o u rce a n d t h e f i n a l d e st i n a t i o n . A d d i t io n a l i n fo r m a t i o n i s p rovided a s ava i l a b le,
- i n c l u d i n g t h e ro u n d t r i p timing ( RTT) a n d a n y c h a n ges i n t h e m a x i m u m t ra n s m i s s i o n u n it ( M T U )
s i ze.

Troubleshooting ports and services


TC P services use soc kets as e n d p o i n t s for co m m u n ication a n d a re m a d e up of an I P a d d ress,
- p rotoco l , and port n u m be r. Services typica l l y l i sten on sta n d a rd ports w h i l e c l i e nts use a ra n d o m
avai l a b l e port. We l l - k n o w n n a m es f o r sta n d a rd po rts a re l i sted i n t h e / e t c /se rvices f i l e .

- The s s c o m m a n d i s used t o d i s p l a y soc ket statistics. I t is s i m i l a r to t h e ne t s t a t c o m m a n d ,


w h i c h is a l so ava i l a b l e but may not b e insta l l e d b y defa u lt.

[student@desktopX
State Recv-Q Send-Q Local Address : Port Peer Address. :. Port
- -)$ ss - ta

LISTEN 0 128 * : sunrpc


O• : ssh *.*
.

LISTEN 0 128
LISTEN 0 100 G 121 . 0 . 0 . 1 : smtp •.*
-

LISTEN 0 128 * : 36889 ...


E> 112 . 25 . X. 10 : ssh 172 . 25 . 254 . 254
ESTAB
LISTEN
0
0
0
128 : : : sunrpc . . I: *59392
-

LISTEN 0 128 0 : : : ssh . . .*


...
LISTEN 0 100 0 : : 1 : smtp
. . . **
-

LISTEN 0 128 : : : 34946

O
-
T h e port used for S S H is l i ste n i n g on a l l 1 Pv4 add resses. The " * " is used to represent " a l l "

O
w h e n refere n c i n g 1 Pv4 a d d resses o r ports.
- T h e port used for S M T P i s l i ste n i n g o n t h e 1 27.0.0.1 1 Pv4 l o o p b a c k i nt e rface.
E) T h e esta b l i s h e d S S H c o n n e c t i o n is o n t h e 172.25.X.1 0 i nterfa ce a n d o r i g i n ates from a syst e m
w i t h a n a d d ress o f 172.25.254.254.
-

- R H1 24- R H EL 7 -en -1 -20140606 2 67

-
-

C h a pter 1 1 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g

O The port u s e d for S S H i s l i ste n i n g o n a l l 1 Pv 6 a d d resses. The " : : " syntax is u sed to represent
a l l 1 Pv 6 i nterfa ces.
-
O The port u s e d for S M T P is l i ste n i n g o n t h e ::1 1 Pv6 loopback i nte rfa ce.

Options for ss and n e t s t at


Option Desc r i p t i o n
-n S h ow n u m be rs i n stead of names for i nte rfaces and ports.
-t S h ow TC P sockets.
-u S h ow U D P soc kets.
-I S h ow o n l y l iste n i n g sockets. -

-a S h ow a l l ( l iste n i n g and esta b l i s h e d ) s o c kets.

-p S h ow the process using t h e soc kets.

R References
ip - link(8), ip - add ress(8), i p - route(8), ip(8), ping(8), t racepath(8),
t race r ou t e(8), ss(8), a n d n e t s t at (8) man pages

A d d i ti o n a l i nfo r m a t i o n may b e ava i l a b l e in the c h a pter o n config u r i n g networki n g in


t h e Red Hat Enterprise Linux Networking Guide for Red H a t E n t e r p r ise L i n u x 7, w h i c h
ca n b e fo u n d at
h t t p ://d ocs. red ha t.com/

268 R H 1 24- R H E L7-en-1-20140606 -

-
-

Practice: Exa m i n i n g Network Config u ra t i o n


-

P ra ct i ce: E xa m i n i n g N etwo r k Confi g u ra t i o n


-

-
Guided exercise
I n t h i s l a b , you w i l l exa m i n e t h e network confi g u ra t i o n of t h e c u r re n t syste m .

Outcomes:
I d entify the c u rre n t network i nterfa ces and basic network a d d resses.

- Before you begin ...


Reset yo u r s e rverX syst e m .

- D 1. D i s p l a y t h e c u rrent I P a d d ress a n d n et m a s k f o r a l l i nte rfaces.

[student@serverX -]$ ip addr


1 : lo : <LOOPBAC K , UP, LOWER_UP> mtu 65536 qdisc noqueue state UN KNOWN
link/loopback 00 : 00 : 00 : 00 : 00 : 00 brd 00 : 00 : 00 : 00 : 00 : 00
-

inet 127 . 0 . 0 . 1/8 scope host lo


valid_lft forever preferred_lft forever
inet6 : : 1/128 scope host
valid_lft forever preferred_lft forever
-

2 : eth0 : <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
qlen 1000
link/ether 52 : 54 : 00 : 00 : 00 : 0b brd ff : ff : ff : ff : ff : ff
inet 172.25.X.11/24 brd 172 . 25 .X. 255 scope global dynamic eth0
-

valid_lft 12704sec preferred_lft 12704sec


inet6 fe80 : : 5054 : ff : fe00 : b/64 scope link
valid_lft forever preferred_lft forever
-

-
D 2. D i s p l a y the stat i s t i cs for the ethO i nte rfa ce.

[student@serverX -]$ ip -s link show e t h 0


2 : eth0 : <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
mode DEFAULT qlen 1000
-

link/ether 52 : 54 : 00 : 00 : 00 : 0b brd ff : ff : ff : ff : ff : ff
RX : bytes packets errors dropped overrun mcast
418398 4588 0 0 0 0
TX : bytes packets errors dropped carrier collsns
-

360733 1730 0 0 0 0
-

D 3. D i s p l a y the routi n g i nf o r m a t i o n .

[student@serverx -]$ ip route


-

default via 172 . 25 .X . 254 dev eth0 proto static met ric 1024
-
172 . 25 .X. 0/24 dev eth0 proto kernel scope link src 172 . 25 .X. 11
D 4. Ve rify t h a t t h e ro uter is access i b l e.

[student@serverX -]$ ping - c3 172 . 25 . X . 254


-

PING 172 . 25 .X. 254 ( 172 . 25 .X . 254) 56( 84 ) bytes of data .


64 bytes from 172 . 25 .X. 254 : icmp_seq=1 ttl=64 time=0 . 489 ms
64 bytes from 172 . 25 . X. 254 : icmp_seq=2 ttl=64 time=0 . 510 ms
64 bytes from 172 . 25 .X. 254 : icmp_seq=3 ttl=64 time=0 . 458 ms
-

- RH124- R H E L 7-en-1 -20140606 269

-
-

C h a pte r 11 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g

- - - 172 . 25 .X. 254 ping statistics - - -


3 packets transmitted, 3 received, 0% packet loss , time 1999ms
-

rtt min/avg/max/mdev 0 . 458/0 . 485/0 . 510/0 . 033 ms


=
-

0 5. Show a l l t h e h o ps between the l oca l system a n d c l a s s room .exa m p l e.co m .

[student@serverX ] $ t racepat h
-

1 : classroom . example . com 0 . 522ms ! H


class room . example . com

Resume : pmtu 65535


-

0 6. D i s p l a y the liste n i n g TCP soc kets o n the loca l syste m .

[student@serverx -]$ s s - lt
-

State Recv-Q Send -Q Local Address : Port Peer Address .: Port


LISTEN 0 128 * : 55630 * . **
LISTEN 0 128 * : sunrpc *.
LISTEN 0 128 * : ssh * *
-

LISTEN 0 100 127 . 0 . 0 . l : smtp


LISTEN 0 128 : : : sunrpc . . .*
LISTEN 0 128 : : : ssh ...*
-

LISTEN 0 128 : : : 33079


LISTEN 0 100 : : 1 : smtp -

--

270 R H 1 24- R H E L 7 - e n -1 -20140606 -

-
-

Confi g u r i n g N etwo r k i n g w i t h nmcli


-

Co nfi g u ri n g N etwo r k i n g wit h nmc li


-

-
Objectives
After c o m p l et i n g t h i s sect i o n , st u d e nts s h o u l d be a b l e to m a n a g e network sett i n g s a n d devices
w i t h nmcli and N etwo r k M a n a g e r.

NetworkManager
-
N etwo r k M a n a g e r i s a d a e m o n t h a t m o n itors a n d m a n a g es network sett i n gs. In a d d i t i o n to t h e
d a e m o n , t h e re i s a G N O M E N o t i f i c a t i o n A rea a p p l et t h a t p rovi d es network sta t u s i nfo r m a t i o n .
Co m m a n d - l i n e a n d g ra p h i ca l too l s ta l k to N etwo r k M a n a g e r a n d s a v e confi g u ra t i o n f i l e s i n t h e
-
/ e t c / sysconfig/netwo r k - s c r i p t s d i recto ry.

A device is a n etwo r k interfa ce. A connection is a confi g u ra t i o n used for a device w h i c h is m a d e


u p o f a co l l ection o f sett i n gs. M u l t i p l e c o n n e c t i o n s m a y exist for a d ev i ce, but o n l y o n e may b e
-
a ctive a t a t i me. Fo r exa m p le, a syste m may n o r m a l ly be c o n n ected to a n etwo r k w i t h sett i n g s
p rov i d e d by D H C P. Occa sio n a l l y, t h a t syst e m needs t o be c o n n ected to a l a b or d a t a center
network, which only uses sta t i c netwo r k i n g . I n stead of c h a n g i n g t h e config u ra t i o n m a n u a l l y, e a c h
confi g u ra t i o n can be stored a s a s e p a rate co n n ect i o n .

- Viewing network information with nmcli


To d i s p l ay a l i st o f a l l connect i o n s , u s e nmcli con show. To l i st o n l y t h e active connections, a d d
t h e - - ac t ive opt i o n .
-

[ root@desktopX -]# nmcli c o n s how


NAME UUID TYPE DEVICE
static -eth0 f3e8dd32-3c9d -48f6- 9066-551e5b6e612d 802-3-ethernet eth0
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet
-

guest f601ca8a-6647-4188- a431-dab48cc63bf4 802-11-wireless wlp3s0


[ root@desktopX -]# nmcli con s how - - act ive
NAME UUID TYPE DEVICE
static-eth0 f3e8dd32-3c9d -48f6-9066-551e5b6e612d 802-3-ethernet eth0
-

guest f601ca8a-6647 -4188-a431-dab48cc63bf4 802-11-wireless wlp3s0


- L_ �������·--- -��

Specify a con nect i o n I D (na me) to s e e t h e deta i l s of t h a t c o n n e c t i o n . T h e l owercase sett i n g s


represe n t t h e config u ra t i o n of t h e c o n nect i o n . Sett ing a n d p ro p e rty n a m e s a re d e f i n e d i n t h e
-
nm - s e t t ings(5) m a n page. T h e u p percase sett i n g s a re act ive data.

[ root@desktopX -]# nmcli con show " s t atic - e t h 0 "

ipv4 . method : manual


-

ipv4 . dns : 172 . 25 . 254 . 254, 8 . 8 . 8 . 8


ipv4 . dns-search :
ipv4 . addresses : { ip 172 . 25 . X. 10/24, gw 172 . 25 .X. 254 }
-

ipv4 . routes :
=

ipv4 . ignore-auto- routes : no


=

ipv4 . ignore-auto-dns : no
ipv4 . dhcp-client-id :
-

ipv4 . dhcp- send- hostname : yes


ipv4 . dhcp-hostname :
ipv4 . never-default : no
ipv4 . may-fail : yes
-

ipv6 . method : auto


-

- R H 1 24- R H E L7-en-1-20140606 271

-
-

C h a pte r 1 1 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g

I ...
-

The nmcli com m a n d can a l so be used to s h ow d evice stat u s a n d d eta i l s.

[ root@desktopX -]# nmcli d e v s t a t u s


DEVICE TYPE STATE CONNECTION
-

eth0 ethernet connected static- eth0


wlp3s0 wifi connected guest
lo loopback unmanaged
[ root@desktopX -]# nmcli dev show ethe
-

GENERAL . DEVICE : eth0


GENERAL . TYPE : ethernet
GENERAL . HWADDR : 52 : 54 : 00 : 00 : 00 : 0A
GENERAL . MTU : 1500
-

GENERAL . STATE : 100 ( connected )


GENERAL . CONNECTION : static -eth0
GENERAL . CON-PATH : /org/freedesktop/NetworkManager/
-

Activeconnection/1
WIRED-PROPERTIES . CARRIER : on
IP4 . ADDRESS [1] : ip 172 . 25 .X. 10/24, gw 172 . 25 .X. 254
IP4 . DNS [1] : 172 . 25 . 254 . 254
-
=

IP6 .ADDRESS[1] : ip fea0 : : 5054 : ff : fe00 : b/64, gw :


=

= = :

Creating network connections with nmc li


-
W h e n creat i n g a new con n ection w i t h nmcli, t h e o rd e r of t h e a rg u m e n t s i s i m portant. T h e
c o m m o n a rg u m e nts a p p e a r f i rst a n d m u st i n c l u d e t h e t y p e a n d interface. N ext, spec ify a ny type­
specific a rg u m e nts and f i n a l l y spec ify the IP a d d ress, p refix, and gateway i nformat i o n . M u l t i p l e I P
-
a d d resses m a y b e specified for a s i n g l e d evice. A d d it i o n a l sett i n g s s u c h a s a D N S server a re set
as modificat i o n s once the connection e x i sts.

-
E xa m p l e s of c reat i n g new c o n n ec t i o n s
Fo l l ow a l o n g w i t h t h e n e x t steps w h i l e yo u r i n st r u ctor d i scusses n m c l i sy n t a x .

1. Defi n e a n e w connection n a m e d "defa u l t " w h i c h w i l l a utoco n n ect a s a n E t h e r n et c o n n ect i o n -

o n t h e et h O device u s i n g D H C P.

[ root@desktopX -]# nmcli con add con - name " default " t ype e t h e r n e t ifname ethe
-

2. C reate a new co n nection named "static" and spec ify t h e IP a d d ress and g ateway. Do not -

a utoco n n ect.

[ root@desktopX -]# nmcli con a d d con - n ame " s tatic " ifname e t h e a u t oconnect no type -

e t h e r n e t ip4 172 . 25 . X . 10/24 gw4 172 . 25 . X . 254

-
3. The syste m w i l l a utoco n n ect with the D H C P co n n ect i o n a t boot. C h a n g e to t h e stat i c
con n e c t i o n .

[ root@desktopX -]# nmcli c o n u p " s t atic "


-

4. C h a n g e b a c k to t h e D H C P co n n e ct i o n . -

[ root@desktopX -]# nmcli c o n u p " default "


-

-
272 R H 1 24- R H E L7-e n-1-20140606

-
-

M o d ify i n g n etwo r k inte rfa ces with nmcli


-

-
Important
I f t h e static c o n n ection is l ost, t h e defa u l t c o n n e c t i o n w i l l atte m pt to a utoco n nect. To
a d m i n istrat i ve l y d is a b l e a n i n t e rface a n d p revent a ny a utoco n n e ct i o n , use nmcli dev
-
disconnect DEVICENAME.

-
Type o p t i o n s
Type o p t i o n s depend o n t h e type used. A n e t h e r n et-ty pe c o n n ection may o pt i o n a l l y s pecify a
M AC a d d ress for t h e c o n n ection. A wifi-type c o n n ection m u st specify t h e 5 5 1 0 a n d m a y s pecify
-
a d d it i o n a l options. M a ny ot h e r types a re ava i l a b l e, i n c l u d i n g bridge, bond, tea m , VPN, and V L A N .
To view a l l t h e o p t i o n s , use nmcli c o n a d d help.

[root@desktopX -]# nmcli con a d d help


Usage : nmcli connection add { ARGUMENTS I help }
-

ARGUMENTS COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS


COMMON_OPTIONS :
- : =

type <type>
ifname <interface name> I " * "
[con- name <connection name>
-

[autoconnect yes l no]


-
[ save yes l no]
TYPE_SPECIFIC_OPTIONS :
ethernet : [mac <MAC address>
[cloned -mac <cloned MAC address>
[mtu <MTU>
-

Modifying network interfaces with nmcli


-

-
A n exist i n g c o n n e ct i o n m a y b e mod ified w i t h nmcli c o n mod a rg u m e nts. T h e a rg u m e nts a re
sets of key/va l u e p a i rs. The key i n c l u d es a sett i n g n a m e a n d a p rope rty n a me. U s e nmcli con
s how " < ID> " to see a l ist of c u rrent va l u es for a c o n n e c t i o n . The nm - s e t t in g s ( 5 ) man page
-
documents t h e sett i n g and property n a m e s and u s a g e.

[root@desktopX -]# nmcli con


connection . id : static
show " st a t ic "

connection . uuid : f3e8dd32- 3c9d -48f6-9066-551e5b6e612d


-

connection . interface- name : eth0


connection . type : 802-3-ethernet
connection . autoconnect : yes
-

connection . timestamp : 1394905322


-
connection . read-only : no

E xa m p l es of c o n n e c t i o n m o d ificat i o n s
-
Fo l l ow along w i t h t h e n ext ste ps w h i l e you r i ns t r u ctor d i s c u sses nmcli syntax.

1. Tu r n off autoco n n ect.

[ root@desktopX -]# nmcli con


-

mod " static " connect ion . autoconnect no

- R H1 24- R H E L 7-en-1-20140606 273

-
-

C h a pter 1 1 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g


-

2. Specify a D N S server.

I [ root@desktopX -]# nmcli con mod


---- -- ----- - --���

J
-
" static " ipv4 . dn s 172 . 25 . X . 254
i __ _ _

3. Some confi g u ra t i o n a rg u me nts m a y h ave va l u es a d d e d o r remove d . Add a +/- sy m b o l i n -

front o f t h e a rg u m e nt. A d d a seco n d a ry D N S server.

I [ root@desktopX -]# nmcli con mod " s t a t ic " +ipv4 . dn s 8 . 8 . 8 . 8 -

4. Repl ace t h e stat i c I P a d d ress a n d gateway. -

I
[ root@desktopX -]#
r- --- --
1 nmcli con mod " s tatic " ipv4 . ad d r e s s e s " 17 2 . 25 . X . 10/24
112 . 25 . x . 254 " -
!
L- ------- ---- --��-- --------'

5. Add a seco n d a r y IP a d d ress w i t h o u t a gateway.

I [ root@desktopX -]# nmcli con mod


-

" st a t i c " +ipv4 . ad d r e s s e s 10 . 10 . 10 . 10/16


l. _ _ _ _ _ _ __________

Important
T h e nmcli con mod w i l l save t h e sett i n g to t h e config u ra t i o n f i l es. To act ivate t h e -

c h a nges, t h e c o n n e c t i o n n e e d s to b e activated o r react ivated.

[ root@desktopX -]# nmcli con u p " s t atic "


-

Summary of nmcli commands


-

-
B a s i c device a n d con n e c t i o n com m a n d s for nmcli:

nmcli commands
-
Command Use
n m c l i dev status L i st a l l d evices.
-
n m c l i con s h ow L i st a l l c o n n e ct i o n s .
n m c l i con u p " < I D>" Activate a c o n n e ct i o n .
n m c l i con d o w n " < I D > " Deact ivate a c o n n e c t i o n . T h e con nect i o n w i l l resta rt i f -

a utoco n n ect i s yes.


n m c l i dev d i s < D EV> B r i n g down a n i nte rfa ce and tem pora r i l y d i s a b l e a utocon nect.
-

n m c l i net off D i sa b l e a l l m a n a g e d i nte rfaces.


n m c l i con a d d . . . Add a n e w c o n n e ct i o n .
-
n m c l i c o n m o d " < I D> " . . . M o d ify a co n n e ct i o n .
nmcli con del "<I D>" D e l ete a co n ne ct i o n .
-

274 R H 1 24- R H E L 7 - e n -1-20140606 -

-
-

S u m m a ry of nmcli com m a n d s
-

k?S-J
< �'
Note
-

T h e nmcli c o m m a n d a l s o h a s a n i nt e ractive edit m o d e. For a g ra p h i c a l i nte rfa ce, use


n m - c o n n e c t io n - ed i t o r .
-

-
References
nmcli(1 ), nmcli - examples(S), a n d nm - s e t t in g s ( S ) m a n p a g es

- A d d i t i o n a l i nfo r m a t i o n m a y be a v a i l a b l e i n t h e sect i o n o n u s i n g t h e N etwo r k M a n a g e r


c o m m a n d l i n e t o o l n m c l i i n t h e Red Hat Enterprise Linux Networking Guide for Red H a t
E nterprise L i n u x 7, w h i c h c a n b e fo u n d a t
- http://docs.re d h a t.com/

- R H 1 24- R H E L 7-en - 1 -20 1 40606 275

-
-

C h a pte r 1 1 . M a n a g i n g Red Hat Enterprise L i n u x N etwo r k i n g

P ra ct i ce: Config u ri n g N etwo r k i n g wit h nmcli


-

Guide d exercise
-

I n t h i s l a b , you w i l l confi g u re n etwo r k sett i n g s u s i n g nmcli.

Outcomes: -

Convert a system from DHCP to static confi g u ra t i o n .

Before you begin. . . -

R e s e t yo u r serverX system.

D 1. View network sett i n g s using nmcli. -

D 1 .1 . S h ow a l l connections.

[student@serverx -]$ nmcli c o n show


-

NAME UUID TYPE DEVICE


System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
D 1.2. D i s p lay all confi g u ra t i o n sett i n g s for t h e active c o n n ec t i o n .

[student@serverx -]$ nmcli


-

connection . id : System eth0


con show " System e t h a "

connection . uuid : 5fb06bd0-0bb0- 7ffb-45f1-


d6edd65f3e03
connection . interface-name : eth0
-

connection . type : 802-3-ethernet


connection . autoconnect : yes
connection . timestamp : 1394813303
-

connection . read-only : no
connection . permissions :
IP4 . ADDRESS [1] : ip 172 . 25 .X . 11/24, gw
-

172 . 25 .X. 254


=

IP4 . DNS[1] : 172 . 25 . 254 . 254


=

IP4 . DOMAIN [1] : example . com


-

D 1 .3. S how device status.

[student@serverX -]$ n m c l i dev s t a t u s


DEVICE TYPE STATE CONNECTION
-

eth0 ethernet connected System eth0


lo loopback unmanaged -

D 1 .4. D i s p l a y t h e sett i n g s for t h e et h O device.

[student@serverX -]$
-

GENERAL . DEVICE : eth0


nmcli dev show eth0

GENERAL . TYPE : ethernet


GENERAL . HWADDR : 52 : 54 : 00 : 00 : 00 : 06
GENERAL . MTU : 1500
-

GENERAL . STATE : 100 ( connected )


-

276 R H 1 24- R H E L7-en-1 -20140606 -

-
-

G u i d e d exercise

GENERAL . CONNECTION : System eth0


-

GENERAL . CON-PATH : /org/freedesktop/NetworkManager/


Activeconnection/1
WIRED- PROPERTIES . CARRIER : on
IP4 . ADDRESS[1] : ip 172 . 25 .X. 11/24, gw
-

172 . 25 .X. 254


=

IP4 . DNS [l] : 172 . 25 . 254 . 254


IP4 . DOMAIN [l] : example . com
-

IP6 . ADDRESS [l] : ip fe80 : : 5054 : ff : fe00 : b/64, gw


=

-
L_ ______.

D 2. C reate a sta t i c con nect i o n with t h e same 1 Pv4 a d d ress, netwo r k prefix, and defa u l t
- g ateway. N a m e t h e n e w co n n ection static-ethO.

[ student@serverX -]$ sudo nmcli con add con - name " s tatic - et h 0 " ifname eth0 type
Connection ' static-eth0 ' ( f3e8dd32- 3c9d -48f6- 9066-551e5b6e612d ) successfully
ethernet ip4 172 . 25 . X . 11/24 gw4 172 . 25 . X . 254

added .
-

j [student@serverX -]$
D 3. M o d ify the new c o n n ecti o n to add t h e D N S sett i n g .

_.,
s u d o nmcli con m o d " st a t ic - et h0 " ipv4 . dn s 172 . 25 . 254 . 254
�----

-
D 4. D i s p l a y a n d a c t i vate t h e new c o n n e c t i o n .

D 4.1 . V i ew a l l c o n n e c t i o n s.

[student@serverX -]$ nmcli con show


NAME UUID TYPE DEVICE
-

static-eth0 f3e8dd32-3c9d -48f6-9066-551e5b6e612d 802-3-ethernet


- System eth0 5fb06bd0-0bb0- 7ffb-45fl-d6edd65f3e03 802-3-ethernet eth0
D 4 . 2 . V i ew t h e a c t i v e connection.
-

[ student@serverX -]$ nmcli c o n show - - ac t ive


-
System eth0 5fb06bd0-0bb0- 7ffb-45fl-d6edd65f3e03 802-3-ethernet eth0
D 4 . 3 . Activate t h e new c o n n e c t i o n .

[ student@serverX -]$ s u d o nmcli con u p " static - et h 0 "


-

Connection successfully activated ( D - Bus active path : /org/freedesktop/


- NetworkManager/Activeconnection/3 )
D 4.4. View t h e active connection.

[student@serverX -]$ nmcli con show - - ac t ive


-

NAME UUID TYPE DEVICE


L_
- static-eth0 f3e8dd32-3c9d -48f6-9066-551e5b6e612d 802-3-ethernet eth0
__ ___��--

D 5. Test the co n n ectivity u s i n g the new network a d d resses.


-

D 5.1 . Ve rify t h e I P a d d ress.

- R H1 24- R H E L7-en-1-20140606 277

-
-

C h a pter 1 1 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g

[student@serverx - ] $ ip add r show ethG


-

2 : eth0 : <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc pfifo_fast


UP qlen 1000
link/ether 52 : 54 : 00 : 00 : 00 : 0b brd ff : ff : ff : ff : ff : ff
-

inet 172 . 25 .X. 11/24 brd 172 . 25 .X. 255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80 : : 5054 : ff : fe00 : b/64 scope link
valid_lft forever preferred_lft forever
-

D 5.2. Ve rify t h e defa u l t g ateway.

[student@serverX - ] $ ip route
default via 172 . 25 .X. 254 dev eth0 proto static metric 1024
-

172 . 25 .X. 0/24 dev eth0 proto kernel scope link src 172 . 25 .X . 11
-

D 5.3. P i n g t h e D N S a d d ress.

[student@serverx - ] $ ping - c3 172 . 25 . 254 . 254


PING 172 . 25 . 254 . 254 ( 172 . 25 . 254 . 254} 56( 84} bytes of data .
-

64 bytes from 172 . 25 . 254 . 254 : icmp_seq=1 ttl=64 time=0 . 419 ms


64 bytes from 172 . 25 . 254 . 254 : icmp_seq=2 ttl=64 time=0 . 598 ms
64 bytes from 172 . 25 . 254 . 254 : icmp_seq=3 ttl=64 time=0 . 503 ms
- - - 172 . 25 . 254 . 254 ping statistics - - -
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0 . 419/0 . 506/0 . 598/0 . 077 ms
-

-
D 6. Config u re the o ri g i n a l co n n ection so that it does n ot sta rt at boot a n d verify t h a t t h e
stat i c con nect i o n i s used w h e n t h e system reboots.

D 6.1 . D i sa b l e t h e o r i g i n a l c o n n e c t i o n f r o m a u tosta rt i n g at boot. -

[student@serverx - ] $ sudo nmcli


> connection . autoconnect no
con mod " System eth0" \
-

D 6.2. Re boot t h e system.

I
-

I [ student@serverX - ] $ reboot
-

D 6.3. V i ew t h e a ct ive c o n n e c t i o n .

[ student@serverx - ] $ nmcli con show - - ac t ive


NAME UUID TYPE DEVICE
-

static- eth0 f3e8dd32-3c9d -4Bf6-9066-551e5b6e612d 802-3-ethernet eth0


-

27 8 RH124- R H E L 7 - e n -1-20140606 -

-
-

Edit i n g N etwork Confi g u ration F i l es


-

Ed it i n g N etwo rk Confi g u rat i o n F i l es


-

-
Objectives
After co m p l et i n g t h i s sect i o n , s t u d e nts s h o u l d be a b l e to m o d ify n etwork sett i n g s by e d i t i n g t h e
confi g u ra t i o n f i l es.
-

Modifying network configuration


It is a l so poss i b l e to confi g u re t h e n etwork by e d i t i n g i nterface config u ra t i o n f i l es. I nte rface
-
confi g u ra t i o n f i l es control the softwa re i nte rfaces for i n d iv id u a l n etwo rk devices. These files a re
u s u a l l y n a m ed /et c/sysconfig/netwo r k - sc r i p t s/ifc f g - < n ame>, w h e re < n a m e > refers
to the n a m e of the device o r c o n n ec t i o n t h a t t h e confi g u ra t i o n f i l e controls. The fo l l owing a re
-
sta n d a rd va r i a b l es fo u n d i n t h e f i l e used for static or d y n a m i c confi g u ra t i o n .

Configuration Options for i fcfg File

Static Dynamic Either


-

BOOTPROTO=none BOOTPROTO=dhcp DEVICE=eth0


-
I PADDR0=172 . 25 . X . 10 NAME= " System e t h0 "

PREF IX0=24 ON BOOT=yes

GATEWAY0=172 . 25 . X . 254 U U I D=f3e8dd32 - 3 . . .

- D E FROUTE=yes USERCT L=yes

DNS1=172 . 25 . 254 . 254


-

In the stat i c sett i n g s , va r i a b l es for I P a d d ress, p refi x , a n d g ateway have a n u m be r at t h e e n d . T h i s


- a l l ows m u l t i p l e s e t s of va l u es to b e a s s i g n e d to t h e i nt e rface. The D N S va r i a b l e a l so h a s a n u m be r
w h i c h i s u s e d t o spec ify t h e o r d e r of l o o k u p w h e n m u l t i p l e se rvers a re s p e c ified.

- Afte r m o d ify i n g t h e config u ra t i o n f i les, r u n nmcli con reload to m a ke Netwo r k M a n a g e r rea d


t h e config u ra ti o n c h a nges. T h e i nte rfa ce st i l l needs t o b e resta rted fo r c h a n g es t o ta ke effect.

( root@serverx -]#
[ root@serverX -]#
- nmcli con reload

( root@serverX -]#
nmcli con down " System e t h a "
nmcli c o n u p "System eth0 "

R References
-
nmcli(1) m a n page

A d d i t io n a l information m a y b e ava i l a b l e i n t h e c h a pt e r o n confi g u r i n g netwo r k i n g i n


- t h e Red Hat Enterprise Linux Networking Guide f o r Red H a t E n t e r p r i s e L i n u x 7, w h i c h
c a n b e fou n d a t
http://d oc s . red h a t .com/
-

- R H 1 24- R H E L 7-en-1 -20140606 279

-
-

C h a pter 1 1 . M a n a g i n g Red Hat Enterprise L i n u x N etwo r k i n g


-

P ract i ce: Ed it i n g N etwo rk Confi g u ra t i o n Fi l es


-

Guide d exercise -

I n t h i s l a b , you w i l l edit netwo r k config u ra t i o n f i l es.


-

Outcomes:
A n a d d i t i o n a l n etwo r k a d d ress added to each syst e m .
-

Before you begin. . .


R e s e t yo u r s e r v e r X a n d d e s ktopX syste ms.
-

D 1. As t h e root user, edit t h e / e t c / sysconfig/netwo r k - s c ri p t s /ifcfg - et h 0 o n


s e rverX to a d d a n a d d i t i o n a l a d d ress o f 10 . 0 . X . 1/24.
-
D 1 .1 . A p p e n d a n e n t ry to t h e f i l e to specify t h e 1 Pv4 a d d ress.

[ root@serverx - ] # echo " I PADDR1=19 . 9 . X . 1 " >> /etc/sysconfig/netwo r k ­ -

scripts/ifcfg - e t h e

-
D 1.2. A p p e n d a n e n t ry to t h e file to s pe c i fy t h e network p ref i x .

[root@serverx
-- - -· --� - � - ------ ·

- ] # echo " PREFIX1=24" » /etc/sysconfig/netwo r k - s c r i p t s /


-
ifcfg - e t h a

D 2. Activate t h e new a d d ress. -

D 2.1 . R e l o a d t h e config u rat i o n c h a n ges.

I [ root@serverx - ] # nmcli con reload


-

D 2.2. Resta rt t h e c o n n e c t i o n w i t h t h e new sett i n g s . -

[ root@serverx
I - ] # nmcli· c o n u p " s y s te m e t h a "
_______________ _____ ______ ___.
-

D 3. A s the root user, e d it the / e t c / sysconfig/netwo r k - sc ript s/ifcfg - e t h 0 on


desktopX to add an a d d it i o n a l a d d ress of 10 . 0 . X. 2/24 a n d l o a d t h e new confi g u ra t i o n . -

D 3.1 . M odify t h e f i l e t o a d d t h e 1 Pv4 a n d n etwork p refix.

[ root@desktopX - ] #
-

e c h o " I PADDR1=10 . 0 . X . 2 " >> /etc/sysconfig/netwo r k ­

[ root@desktopX - ] #
L
scripts/ifcfg - e t h e
e c h o " P REFIX1=24 " >> /etc/sysconfig/netwo r k - s c ripts/
-
ifcfg - et h e
______ .

D 3.2. Reload t h e config u ra t i o n c h a nges. -

[ root@desktopX - ] # nmcli con reload


-

280 R H 1 24- R H E L7-en-1-20140606 -

-
-

G u i d e d exercise
-

D 3.3. B r i n g u p t h e connection w i t h t h e n ew sett i n g s .

[ root@desktopX
I
-
� ] # nmcli con up " System e t h 0 "

- D 4. Test t h e c o n n ect ivity u s i n g t h e new network a d d resses.

D 4.1 . O n serverX, verify t h e I P a d d ress.

I [ root@serverX
-

- ] # ip add r

-
D 4.2. O n serverX, p i n g t h e new a d d ress of d e s ktopX.

-
I [ root@serverX - ] # ping 10 . 0 . x . 2

D 4.3. O n d es ktopX, verify t h e I P a d d ress.

I [ root@desktopX
-

- ] # ip add r

-
D 4.4. O n d e s ktopX, p i n g t h e n e w a d d ress o f serverX.

- [ root@desktopX -]# p i n g 10 . 0 . x . 1

- R H 1 24- R H E L7-en-1 -20140606 2 81

-
-
-
C h a pter 11. M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g
-
Confi g u ri n g H ost N a mes a n d N a m e Reso l ut i o n -
Objectives -
-
After co m p l e t i n g t h i s sect i o n , students s h o u l d be a b l e to confi g u re a n d test system host n a m e
a n d n a m e reso l ut i o n .

Changing the syste m host name


The hos t n ame com m a n d d i s p l ays o r t e m p o ra r i l y m o d i fies t h e syste m ' s f u l l y q u a l ified host n a m e. -
[ root@desktopX -]# host n ame
desktopX . example . com -
A static h ost n a m e m a y be specified i n the / e t c / h o s t name f i l e. The hos t n amec t l c o m m a n d
-
-
i s used to mod ify t h i s f i l e a n d may be used t o view t h e sta t u s of t h e syst e m ' s f u l l y q u a l ified host
n a me. I f t h i s f i l e does not exist, the host n a m e i s set by a reverse DNS q u e r y o n ce the i nte rfa ce
has an IP a d d ress a ss i g n e d .

[ root@desktopX -]# host namec tl set - host name desktopX . example . com
[ root@desktopX -]# host namec tl s t a t u s
Static hostname : desktopX . example . com
Icon name : computer
-
Chassis : n/a
Machine ID : 9f6fb63045a845d79e5e870b914c61c9
Boot ID : aa6c3259825e4b8c92bd0f601089ddf7
-
Virtualization : kvm
Operating System : Red Hat Enterprise Linux Server 7 . 0 ( Maipo)
CPE OS Name : cpe : /o : redhat : enterprise_linux : 7 . 0 : beta : server
Kernel : Linux 3 . 10 . 0-97 . el7 . x86_64
-
Architecture : x86_64
[ root@desktopX -]# cat /etc/host name
desktopX . example . com
-
-
' Important
The static host n a m e is stored i n / e t c / h o s t n ame. P revious vers i o n s
-
-
of Red H a t Ente r p r i s e L i n u x stored t h e h o s t n a m e a s a va r i a b l e i n t h e
/ etc / sysconfig/netwo r k f i l e.

Configuring name resolution -


-
T h e stub resolver is u s e d to co nvert host n a m e s to I P a d d resses or t h e reverse. T h e contents of
t h e f i l e /etc/hos t s a re c h e c ked fi rst.

[ root@desktopX -]# cat /etc/ho s t s


127 . 0 . 0 . 1
: :1
localhost localhost . localdomain localhost4 localhost4 . localdomain4
localhost localhost . localdomain localhost6 localhost6 . localdomain6
172 . 25 . 254 . 254 classroom . example . com
-
172 . 25 . 254 . 254 content . example . com
-
-
-
282 R H 1 24- R H E L 7-e n-1-20140606
-

Confi g u r i n g n a m e reso l ut i o n
-

The g e t e n t hos t s hos tname c o m m a n d c a n be u s e d to t e s t host n a m e reso l ut i o n with t h e


/ e t c / ho s t s fi l e.
-

I f a n e n t ry is not fo u n d i n t h a t f i l e, t h e stub reso lver l o o ks for t h e i nfo rmation from a D N S


n a m ese rve r. T h e / e t c / resolv . c o n f f i l e contro l s h o w t h i s q u e ry is d o n e:
-

• n amese rve r: t h e I P a d d ress of a n a m ese rver to q u e ry. U p to t h ree n a meserver d i rectives m a y


be g iven to provide b a c k u p s i f o n e i s d o w n .
-

• sea r c h : a l ist o f d o m a i n n a m es to try with a s h o rt host n a m e. Both t h i s a n d domain s h o u l d


n o t b e s e t i n t h e s a m e f i l e ; i f t h ey a re, t h e l a st i n stance w i ns. S e e resolv . conf(5) f o r d eta i l s.

[ root@desktopX - ] # cat /etc/resolv . conf


-

Generated by NetworkManager
domain example . com
#

search example . com


-

nameserver 172 . 25 . 254 . 254


-

N etwo r k M a n a g e r w i l l u p d ate the / e t c / r esolv . conf f i l e u s i n g D N S sett i n g s in the c o n n e c t i o n


confi g u ra t i o n f i l es. U s e t h e n m c l i to mod ify t h e connections.

I [ root@desktopX
[ root@desktopX
-
.-- ������ .������
!

i -]# nmcli con mod ID ipv4 . dn s IP

I [ root@desktopX
-] # nmcli con down ID

[ root@desktopX
;;�1"8. B B. B
j
- -] # nmcli con up ID

I -]# cat /etc/sysconfig/networ k - sc ript s/ifcfg - ID

L
The defa u l t behavior of nmcli con mod I D ipv4 . d n s I P i s to re p l ace any prev i o u s D N S
-

sett i n g s w i t h t h e n e w I P l i st prov i d e d . A +/- sy m bo l i n front o f t h e ipv4 . dns a rg u m e n t w i l l a d d


o r remove a n i n d i v id u a l ent ry.

[ root@desktopx
-

- ] # nmcli con mod ID +ipv4 . dn s IP

-
The host HOSTNAME c o m m a n d c a n b e used to test D N S server c o n n ect i vity.

[ root@desktopX - ] # host class room . example . com


classroom . example . com has address 172 . 25 . 254 . 254
[ root@desktopX - ] # host 172 . 25 . 254 . 254
-

-
254 . 254 . 25 . 172 . in-addr . arpa domain name pointer classroom . example . com .

9 Important
I f D H C P is i n use, / e t c / re solv . conf is a utomatica l l y rew ritten a s inte rfaces a re
sta rted, u n l ess you s pecify P E ERDNS=no i n t h e rel eva n t i nterface config u ra t i o n f i l es.
-
The c h a n g e can b e m a d e w i t h nmcli.

-
[ root@desktopX - ] # nmcli con mod "System eth0 " ipv4 . ignore - au t o - d n s yes

- R H1 24- R H E L 7-en-1-20140606 283

-
-

C h a pter 1 1 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g

R References
"'· -�·
-

nmcli(l ), host namec t l(l), hos t s ( 5 ) , g e t e n t (l ) , host(l), a n d r esolv . conf(5) m a n


pages
-
A d d i t i o n a l i nfo r m a t i o n may b e a va i l a b l e i n t h e c h a pter o n config u ri n g host n a mes in
t h e Red Hat Enterprise Linux Networking Guide for Red H a t Enterprise Linux 7, w h i c h
c a n b e fou n d a t -

http ://d o cs.red h a t.com/

284 R H1 24- R H E L7-en-1-20140606 -

-
-

Practice: Confi g u r i n g Host N a m es a n d N a m e Reso l ut i o n


-

P ra ct i ce: Co nfi g u ri n g H ost N a mes a n d N a m e


-

Reso l ut i o n
-

Guide d exercise
- I n t h i s l a b, you w i l l config u re t h e system host n a m e a n d n a m e reso l ut i o n .

O ut c o m e s :
C u sto m ized host n a m e and name reso l ut i o n sett i n g s.

Before you begin ...


- Reset your serverX syst e m .

0 1. View t h e c u rrent h o s t n a m e sett i n gs.


-
0 1 .1 . D i s p l a y t h e cu rrent host n a me.

[student@serverx -]$
serverX. example . com
host n ame
-

-
0 1 .2. D i s p l a y t h e h ost name status.

[ student@serverx -]$ host name c t l s t a t u s


Static hostname : n/a
Transient hostname : serverX. example . com
Icon name : computer
-

Chassis : n/a
Machine I D : 9f6fb63045a845d79e5e870b914c61c9
Boot ID : d4ec3a2e8d3c48749aa82738c0ea946a
-

Operating System : Red Hat Enterprise Linux Server 7 . 0 ( Maipo )


CPE OS Name : cpe : /o : redhat : enterprise_linux : 7 . 0 : beta : server
Kernel : Linux 3 . 10 . 0-97 . el7 . x86_64
L
Architecture : x86_64
-

�������

-
0 2. Set a sta t i c h ost n a m e to match t h e c u r re n t t ra ns i e n t host n a me.

0 2.1 . C h a n g e t h e host n a m e a n d host n a m e config u ration f i l e. R e p l a c e t h e X w i t h your


-
stat i o n n u m be r a n d m atch t h e o u t p u t of t h e p rev i o u s step.

-
I [student@serverx -]$ s u d o h o s t namec tl set - host name se rve rX . example . com
I

0 2.2. V i ew t h e conf i g u ra t i o n f i l e prov i d i n g t h e h ost n a m e at network start.

[student@serverx -]$
-

L
serverX. example . com
cat /etc/host name

0 2.3. D i s p l a y the host n a m e sta t u s .

[student@serverX -]$ host namec tl s t a t u s


Static hostname : serverX. example . com
-

Icon name : computer


-

- R H1 24- R H E L 7-en-1 -20140606 285

-
-

C h a pter 1 1 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g

Chassis : n/a
-

Machine ID : 9f6fb63045a845d79e5e870b914c61c9
Boot ID : d4ec3a2e8d3c48749aa82738c0ea946a
Operating System : Red Hat Enterprise Linux Server 7 . 0 { Maipo )
CPE OS Name : cpe : /o : redhat : enterprise_linux : 7 . 0 : beta : server
-

Kernel : Linux 3 . 10 . 0-97 . el7 . x86_64


Architecture : x86_64 -

D 3. Te m p o ra r i l y c h a n g e the host n a m e. -

D 3.1 . C h a n g e t h e h ost n a m e.

[student@serverx
r--·����---, -
- ] $ sudo host name tes tname

D 3.2. D i s p l ay t h e c u rrent host n a m e. -

[student@serverx
test name
- ] $ host name
-

1 [student@serverX
D 3.3. V i ew the confi g u ra t i o n f i l e p rov i d i n g the host n a m e at n etwo r k sta rt.
-

serverx. example . com


- ] $ cat /etc/ho s t n ame

L___·����--'

D 3.4. Re boot t h e syste m.

I [ student@serverX - ] $
-

reboot

-
D 3.5. D i s p l a y t h e c u rrent host n a m e.

[ student@serverx - ] $
serverX. example . com
host name -

D 4. Add a loca l n i c k n a m e for the c l a ss room server. -

D 4.1 . Look u p t h e I P a d d ress of t h e c l a s s ro o m .exa m p l e.com.

[ student@serverx - ] $ host clas s r oom . example . com


-

classroom . example . com has address 172 . 25 . 254 . 254


-

D 4.2. M o d ify / e t c /hos t s so t h a t the n a m e class has the I P a d d ress 172.25.254.254


a n d can b e used to com m u n i cate w i t h c l a s s room.exa m p l e.co m .

[ student@serverx - ] $ sudo v i /et c/host s


-

[ student@serverX - ] $ cat /etc/host s


127 . 0 . 0 . 1 localhost localhost . localdomain localhost4
localhost4 . localdomain4
-

: :1 localhost localhost . localdomain localhost6


localhost6 . localdomain6
172 . 25 . 254 . 254 classroom . example . com class
-

-
286 R H 1 24- R H EL 7-en-1-20140606

-
-

G u i d e d exercise

172 . 25 . 254 . 254 content . example . com


-

-
D 4.3. Look up the I P a d d ress of the c l ass.

[student@serverX - ] $ host class


-

-
Host class not found : 2 (SERVFAIL)
[student@serverX - ] $ getent hosts class
172 . 25 . 254 . 254 classroom . example . com class l
D 4.4. Ping c l ass.

[student@serverX - ] $ p i n g - c3 class
PING classroom . example . com ( 172 . 25 . 254 . 254) 56( 84 ) bytes of data .
-

64 bytes from classroom . example . com ( 172 . 25 . 254 . 254 ) : icmp_seq=1 ttl =64
time=0 . 397 ms
64 bytes from classroom . example . com ( 172 . 25 . 254 . 254 ) : icmp_seq=2 ttl=64
-

time=0 . 447 ms
64 bytes from classroom . example . com ( 172 . 25 . 254 . 254 ) : icmp_seq=3 ttl=64
-
time=0 . 470 ms
- - - classroom . example . com ping statistics - - -
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0 . 397/0 . 438/0 . 470/0 . 030 ms
-

- R H 1 24- R H E L7-en-1 -20140606 2 87

-
-

C h a pt e r 1 1 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g

L a b: M a n a g i n g Red H at E nt e r p r i se L i n ux
-

N etwo r k i n g
-

Performance checklist
-
I n t h i s l a b , you w i l l config u re b a s i c 1 Pv4 n etwo r k i n g on Red H a t Enterprise L i n u x systems.

Outcomes:
-
T h e p r i m a ry i nte rface h a s two sta t i c I Pv4 a d d resses confi g u re d .

Before you begin. . .


Reset you r desktopX syst e m . -

1. C reate a new connect i o n with a static n etwo rk c o n n e c t i o n u s i n g t h e sett i n g s i n t h e ta b l e. B e


s u re to re p l a ce t h e X w i t h t h e correct n u m be r for you r systems. -

Para m eter Sett i n g


-
Connection name lab
I P a d d ress 172.25.X.1 0/24
Gateway a d d ress 172.25.X.254
D N S a d d ress 172 .25.254.254
-
2. Conf i g u re t h e n e w c o n n e c t i o n to b e a u tostarted. O t h e r c o n n e c t i o n s s h o u l d n o t start
a ut o m a t i ca l l y.
-
3. M o d i fy the new c o n n e c t i o n so that it a l so uses the a d d ress 1 0.0.X.1 /24.

4. Confi g u re t h e hos t s f i l e so t h a t 1 0.0.X.1 can be refere nced as " pr i vate " .


-

5. Reboot t h e system , t h e n r u n l a b netwo r k g r ad e to verify sett i n g s .

288 R H 1 24- R H E L7 - e n -1-20140606 -

-
Solution

Solution
I n t h i s l a b , you w i l l c o n f i g u re b a s i c 1 Pv4 n etwor k i n g o n Red H a t Enterprise L i n u x system s.

Outcomes:
The p r i m a ry i nterface h a s two stat i c 1 Pv4 a d d resses config u re d .

Before you begin ...


Reset you r d e s ktopX system.

1. C reate a new con nection with a sta t i c n etwork c o n n ection u s i n g the sett i n g s in the t a b l e. Be
s u re to r e p l a ce the X with the correct n u m b e r for your systems.

Parameter Setti n g

Con nection n a m e lab

I P a d d ress 172.25.X.1 0/24

Gateway a d d ress 172.25.X.254

D N S a d d ress 172.25.254.254

[ r o o t@d e s k t o p X - ] # nmcli con add con - name lab ifname etho type ethe rnet ip4
172 . 25 . X . 10/24 gw4 172 . 25 . X . 254
[ r oot@d e s k t o p X - ] # nmcli con mod " la b " ipv4 . dns 172 . 25 . 254 . 254

2. Confi g u re the new connection to be a utosta rted. Other connections s h ou l d not sta rt
a u t o m a t i ca l l y.

[ r o o t@d e s k t opX - ] # nmcli con mod " lab" connection . autoconnect yes
[ r oot@d e s k t o p X - ] # nmcli con mod "System ethO" connection . autoconnect no

3. M od ify the new c o n nection so that it a l so uses the a d d ress 1 0.0.X.1 /24.

[ r oot@d e s k topX - ] # nmcli con mod " lab" +ipv4 . addresses 10 . 0 . X . 1/24

Or a ltern ately:

[ root@d e s k t o pX - ] # echo " I PADDR1=10 . 0 . X . 1 " » /etc/sysconfig/netwo r k - s c ripts/ifcfg ­


lab
[ r oot@d e s k t opX - ] # echo " PREFIX1=24" >> /etc/sysconfig/netwo r k - sc ripts/ifcfg- lab

4. Confi g u re t h e host s file so t h at 1 0.0.X.1 ca n be refe renced as " p riva t e " .

[ r oot@d e s k t o p X - ] # echo " 10 . 0 . X . 1 privat e " > > /etc/hosts

5. Re boot t h e system, then run lab ne two r k g rade to verify sett i ngs.

[ r o o t @d e s k t op X - ] # lab netwo r k g rade

R H1 24-RH EL 7-en-1-2 0140606 289


-

C h a pte r 11 . M a n a g i n g Red H a t Enterprise L i n u x N etwo r k i n g


-

S u m m a ry -

N etwo r k i n g Concepts
L ist feat u res of computer netwo r k i n g . -

Va l i d a t i n g N etwork Config u ra ti o n
U s e b a s i c u t i l ities to dete r m i n e c u rrent n etwork confi g u ra t i o n .
-

Confi g u r i n g N etwo r k i n g with nmcli


M a n a g e n etwo r k d evices w i t h com m a n d - l i n e u t i l ities.

Edit i n g N etwo r k Confi g u ra t i o n F i l e s


M od ify n e t w o r k confi g u rati o n f i l es.
-

Config u r i n g H ost N a mes and N a m e Reso l ut i o n


D i s p l ay a n d c h a n g e system host n a m e a n d n a m e res o l ution confi g u ra t i o n .
-

290 R H 1 24- R H E L7-en-1-20140606

-
red h at ®

®
TRAINING

C H A PT E R 1 2

ARCHIVI N G AND COPYI NG FI LES


BETWEEN SYSTEMS

Overview:

Goal To a rch ive a n d copy files from o n e system to a n o t h e r.

Objectives • U se t a r to create new c o m p ressed a rc hive files a n d extract


files from e x i s t i n g arch ive fi les.

• Copy files securely to o r from a remote system r u n n i n g


sshd.

• Secure l y synchro n ize t h e contents of a l o c a l f i l e or


d i rectory with a remote copy.

Sections • M a n a g i n g Compressed t a r Arc h i ves (and P ra c t i ce)

• Copying F i l es Between Systems Securely (a n d Pra ct ice)

• Sync h ro n i z i n g Files Between Systems S e c u re l y (and


Pract ice)

Lab • Archiving a n d Copy i n g F i l es Between Systems

R H 1 24 - R H E L7 -en-1-20140606 2 91
-

C h a pt e r 1 2 . A rc h i v i n g a n d Copy i n g F i l es Betwe e n Syste ms

M a n a g i n g Co m p ressed ta r A rc h ives
-

Objective
-
Aft e r com p l et i n g t h i s sect i o n , students s h o u l d be a b l e to u s e t a r to create new co m p ressed
a rc h ive f i l es and extract files from e x i st i n g a rc h ive f i l es.
-

What is tar?
A r c h i v i n g a n d com press i n g f i l es a re usefu l w h e n c reat i n g b a c k u p s a n d t ra n sfe r r i n g data a c ross a
-
network. O n e of t h e o l d est a n d most c o m m o n co m m a n d s for c rea t i n g a n d w o r k i n g w i t h b a c k u p
a rc h i ves is t h e t a r co m m a n d .

-
W i t h t a r , users can g a t h e r l a rg e s e t s o f f i l es i nto a s i n g l e f i l e (a rc h i ve). T h e a rc h ive ca n b e
c o m p ressed u s i n g gzip, bzip2, o r xz c o m pres s i o n .

T h e t a r c o m m a n d can l ist t h e c o n t e n t s of a rc h ives o r extra c t t h e i r f i l e s to t h e c u rrent syste m . -

E xa m p l es o f h o w to use t h e t a r c o m m a n d a re i n c l u d e d i n t h i s sect i o n .

Operate the t a r com mand


-

To use the tar co m m a n d , one of the t h re e fo l l ow i n g a c t i o n s is req u i re d :


-

· c (create a n a rc h i ve)

· t ( l ist t h e conte nts of an a rc h ive) -

• x (extract an a rc h ive)

-
Co m m o n l y used options a re :

· f fil e name (fi l e n a m e of t h e a rc h ive to operate o n )


-

· v (ve rbos ity; u s e f u l to see w h i c h f i l e s g et a d d e d to o r extracted from t h e a rc h ive)

-
Note
A l e a d i n g - is not req u i re d for ta r o p t i o n s.
-

Archive files and directories with t a r -

Before creat i n g a tar arch ive, verify t h a t t h e re is no ot h e r a rc h ive i n t h e d i rectory w i t h t h e s a m e


n a m e as t h e new a rch ive to be c reated. T h e t a r co m m a n d w i l l ove rwrite a n exist i n g a rc h ive
-
w i t h o u t a ny feed back.

T h e fi rst option to use when c reat i n g a new a rc h ive i s t h e c o pt i o n , fo l l owed by t h e f o pt i o n , t h e n


-
a s i n g l e spa ce, t h e n t h e f i l e n a m e of t h e a rc h ive to be c reated , a n d f i n a l l y t h e l i st o f f i l e s a n d
d i rectories t h a t s h o u l d g e t a d d e d to t h e a rc h ive. T h e a rc h i ve i s c reated i n t h e c u rrent d i rectory
u n l e s s specified otherwi se.
-

In the fo l l ow i n g exa m p l e, an a rchi ve n a m e d a rch ive . tar i s c reated with the contents of f i l e1 ,
f i l e 2 , a n d f i l e3 i n t h e u s e r ' s h o m e d i recto ry.
-

292 R H 1 24- R H E L7-en-1-20140606 -

-
-

List contents of a tar a rc h ive


-

[user@host - ] #
[user@host - ] #
t a r cf archive . t a r file1 file2 file3

archive . tar
ls archive . t a r
-

-
Note
W h e n a rc h i v i n g f i l e s by a bso l ute path n a m es, t h e l e a d i n g I of t h e p a t h is re m oved from
- t h e f i l e n a m e by defa u lt. T h i s h e l ps avoid m i stakes w h i c h cou l d c a u s e i m p o rt a n t f i l es to
b e ove rwritten . F i l es are n o rm a l l y ext ra cted re l a t ive to the c u rrent work i n g d i recto ry of
t h e ta r c o m m a n d .
-

Fo r t a r to be a b l e to a rc h ive t h e s e l ected f i l es, it i s m a n datory t h a t t h e u s e r execut i n g t h e t a r


- com m a n d i s a b l e to read the f i l e(s). Fo r exa m p l e, c reat i n g a n e w a r c h i ve o f t h e / e t c fo l d e r a n d
a l l o f i t s content req u i res root p r i v i l eges, beca u s e o n l y root i s a l lowed to read a l l o f t h e fi les
t h e re. A n u n privi l e g e d user cou l d c reate an a rc h ive of the /etc fo l d e r, b u t the a rc h ive wou l d o m i t
- f i l es w h i c h d o not i n c l u d e rea d p e r m i s s i o n for t h e user a n d it wou l d o m i t d i recto ries w h i c h d o n o t
i n c l u d e both r e a d a n d execute p e r m i s s i o n for t h e user.

C reate t h e t a r a rc h ive / root/e t c . t a r w i t h t h e / e t c d i rectory as content as u s e r root:


-

[ root@host -]# t a r cf /root/etc . t a r /etc


tar : Removing leading ' / ' from member names
-
[ root@host - ] #

I mportant
-

W h i l e t a r sto res owners h i p a n d p e r m i s s i o n s of t h e f i l es, t h e re a re ot h e r att r i b utes that


- a re n ot stored i n t h e t a r a r c h ive by defa u lt, s u c h a s t h e S E L i n u x co ntext and ACLs. To
store t h ose exte n d e d att r i butes i n t h e t a r a rc h ive, t h e - - xat t r s option is req u i red
when c reat i n g an a rc h i ve.
-

-
List contents of a tar archive
To l ist t h e content of a n a rch ive, t h e t a n d f o p t i o n s , acco m p a n ied by t h e a rc h ive to o p e rate, a re
req u i red.
-
L ist t h e content of t h e a rc h ive / root/e t c . t a r :

[ root@host - ] #
etc/
t a r t f /root/et c . t a r

etc/f stab
-

etc/crypt tab
- etc/mt ab

Extract an archive created with tar


-

A t a r a rc h ive s h o u l d n o r m a l l y b e extracted i n a n e m pty d i rectory t o e n s u re i t d o e s not ove rwrite


- a ny e x i st i n g f i l es. I f files a re extracted by root, tar attem pts to preserve the o r i g i n a l user a n d
g ro u p o w n e rs h i p of t h e f i l es. I f a reg u l a r u s e r extracts f i l es u s i n g t a r , t h e ext racted f i l e s a re
ow n e d by t h a t u s e r.
-

- R H 1 24- R H E L 7-en-1-20140606 293

-
-

C h a pter 1 2 . A rc h i v i n g a n d Copy i n g F i l e s Betwe e n Systems


-

Extract t h e a rc h ive / root/e t c . t a r to t h e / ro o t / e t cbackup d i rectory:

[ root@host -]# mkdir / root/etcbackup


[ root@host -]# cd / root/etcbackup
-

[ root@host etcbackup]# tar xf /root/etc . ta r


-

By defa u l t . w h e n f i l es get extracted f r o m a n a rc h ive, t h e u m a s k i s s u b t racted from t h e


permissions of a rc h ive c o n t e n t . T h i s is a secu rity m e a s u re a n d prevents ext racted reg u l a r f i l es
-
from recei v i n g execute p e r m i s s i o n s by defa u lt. To p rese rve t h e p e r m i s s i o n s of an a rc h ived f i l e,
t h e p option i s to be used w h e n extract i n g a n a r c h i ve.

-
Extract the a rc h ive / ro o t /mysc rip t s . tar to the / r oot / s c r i p t s d i rectory w h i l e preserving
t h e p e r m i s s i o n s of t h e ext racted f i l es:

[ root@host -]# m k d i r /root /sc ripts


[ root@host -]# cd / root/scripts
-

[ root@host scripts]# t a r xpf / root/myscript s . t a r


-

Create a com pressed tar archive


-
There a re t h ree d iffe re nt c o m p ress i o n m e t h o d s s u p p o rted by t h e t a r co m m a n d . T h e g z i p
com p ress i o n i s t h e fa stest a n d o l dest one, a n d i s m o s t w i d e l y ava i l a b l e. T h e bz i p2 co m p ression
u s u a l l y leads to s ma l l e r a rc h ive files c o m p a red to gzip and i s less widely ava i l a b l e t h a n g z i p,
-
w h i l e t h e xz c o m p ression method is re l a t i v e l y new, b u t usua l l y offers t h e best c o m p ress ion rat i o
o f t h e met h o d s ava i l a b l e .

. ..... >., -

Note

The effectiveness of a ny com p ress i o n a l g o r i t h m d e p e n d s o n t h e exact n a t u re of t h e
-
d a t a b e i n g c o m p ressed. Data f i l e s t h a t a re a l re a d y c o m p ressed, s u c h a s c o m p ressed
pict u re formats o r r p m f i l es, u s u a l l y lead to a l o w com p ression ratio.

I t i s good practice to u s e a single top- l evel d i recto ry, w h ic h can conta i n o t h e r d i rectories and
fi l es, to s i m p l ify extracti o n of t h e f i l e s i n a n o rg a n ized way.
-

To c reate a co m p ressed t a r a rch ive, o n e of t h e fo l l o w i n g t a r options can be s pecified:

• z for gzip co m p ression (fi l e n a me.t a r.gz o r f i l e n a m e.tgz) -

· j for b z ip 2 com pres s i o n (fi l e n a m e.ta r.bz2)


-
• J for x z c o m p ression (fi l e n a m e.ta r.xz)

C reate (c option) a g z i p-com pressed (z option) t a r a rc h ive / roo t /e t c b ac k u p . t a r . g z of the


-
/ e t c di rectory o n serverX:

1 [ root@serverx - ] $ t a r czf /root/etcbackup . ta r . gz / e t c


-

C reate (c option) a bzi p2-co m p ressed (j option) t a r a rc h ive / root /logbac k u p . t a r . b z 2 of the
/var /log d i rectory o n serverX:

[ root@serverx -]$ t a r c j f /root/logbac kup . t a r . bz 2 /var/log


-

294 R H 1 24- R H E L7-en-1-20140606 -

-
-

Extract a com p ressed t a r a rc h ive


-

C reate (c option) a xz-co m p ressed (J option) t a r a rch ive / ro o t / s s hconfig . t a r . b z 2 of t h e


/ e t c / s s h d i recto ry o n se rve rX:

_J
I [ root@serverX -]$ �J f -�r o�t / sshconfig . t a r . xz / e t c / s s h
-

tar _
_

E xtract a com pressed tar archive


T h e fi rst step w h e n extract i n g a c o m p ressed t a r a rc h ive i s to dete r m i n e w h e re t h e a rc h ived f i l e s
-
s h o u l d be extracted t o , t h e n c reate a n d c h a n g e to t h e ta rget d i rectory. To s u ccessf u l l y extract
t h e a rc h ive, it is u s u a l l y n ot n e cessary to u s e the same c o m p ress i o n option used when creat i n g
t h e a rc h ive, a s t h e t a r com m a n d w i l l dete r m i n e w h i c h c o m p ression w a s used. I t i s va l i d to a d d
-
t h e d e c o m p ression m e t h o d to t h e t a r o p t i o n s a s fol l ows:

Extract (x option) t h e contents of a g z i p-co m p ressed (z o p t i o n ) ta r a r c h i ve named


-
/ r oo t / e t c backu p . t a r . gz to t h e d i rectory / t mp/et c backu p:

[ root@serverx -]$ mkdir /tmp/etcbackup


[ root@serverX -]$ cd /tmp/etcbackup
[ root@serverX etcbackup]$ t a r xzf /root/etcbacku p . t ar . gz
-

- E x t ra ct (x option) t h e contents of a bz i p2-com pressed (j o p t i o n ) t a r a rc h ive n a m e d

1 [ root@serverX -]$
/ root /logbac ku p . t a r . bz2 to t h e d i rectory / t mp/logbac ku p :
�-------- ------.. ----- - ------
-- - - --�

[root@serverX -]$
-
mkdir / tmp/logbackup

I [root@serverX logbackup]#
cd /tmp/logbac kup
t a r xj f /root/logbacku p . t ar . bz 2
!'----------- ----- -
-

Extract (x option) t h e contents of a xz-co m p ressed (J o p t i o n ) t a r a rc h ive n a m e d


/ ro o t / s s hbacku p . t a r . xz to t h e d i rectory / t m p / s s h b a c k u p:

[ root@serverX -]$ mkdir /tmp/sshbackup


- - -- - - - - -- - - �- - - �---- ------- .

I
[ root@serverX -]$ cd /tmp/sshbackup
!

[ root@serverX sshbackup]# t a r xJf /root/sshbacku p . t ar . xz


!
-

-
Note
L i st i n g a co m p ressed t a r a rc h ive works i n t h e s a m e way as l isti n g a n u n c o m p ressed
tar a rc h ive.
-

- Note
A d d i t i o n a l l y, gzip, bzip2, a n d xz c a n b e used i n d e pe n d e n t l y to com press s i n g l e f i l es.
For exa m p l e, g z i p e t c . tar res u l t s i n the com p ressed file e t c . t a r . g z , w h i l e bzip2
-
abc . t a r res u l t s in t h e co m p ressed file abc . t a r . bz2 and xz myarchive . t a r
res u lts i n t h e c o m p ressed fi l e mya r c h ive . t a r . x z .
- T h e corres p o n d i n g deco m p ress co m m a n d s a re g u n z i p , b u n zip2, a n d u n x z . Fo r
exa m p l e, g u n z i p /tmp/e t c . t a r . gz res u lts i n t h e u n com p ressed tar f i l e e t c . t a r ,
w h i l e b u n z i p 2 abc . t a r . b z 2 res u l ts i n t h e u n c o m p ressed t a r f i l e abc . t a r a n d u nxz
-
mya r chive . t a r . xz res u l t s i n t h e u n co m pressed t a r f i l e myar c h ive . t a r .

- R H1 24- R H E L7-en-1-20140606 295

-
-

C h a pt e r 1 2 . Archiving a n d Copy i n g F i l es Between Syste m s

Overview of t a r o ptions
-

-
The t a r co m m a n d has m a n y opt i o n s to u se. The fo l l owing ta b l e l i sts s o m e c o m m o n o p t i o n s a n d
t h e i r mea n i n g s.
-
Overview of tar options

Option Meaning
c C reate a n ew a rc h i ve. -

x Extract from a n ex i st i n g a rc h i ve.


t List t h e contents of a n a rc h ive. -

v Ve rbose; s h ows w h i c h f i l e s get arch ived or extracted.


f F i l e n a m e ; t h i s o pt i o n n e e d s to be fo l l owed by t h e f i l e n a m e of t h e a rc h i ve to -
use/c reate.
p Preserve t h e p e r m i s s i o n s of f i l es a n d d i rectories w h e n extra c t i n g a n a rc h ive,
without s u bt ra ct i n g the u m a s k . -

z U s e gzip c o m p ression ( . t a r . gz) .


j U s e bzip2 c o m p re s s i o n ( . t ar . bz2). bzip2 typica l l y a c h i eves a bett e r -

c o m p ress i o n rat i o t h a n gzip.


J U s e xz c o m p ression ( . t a r . xz). xz ty p i ca l l y a c h i eves a better compress i o n rat i o
-
t h a n bzip2.

R References -

tar(1), gzip(1 ), g u n z ip(1 ), bzip2(1 ) , bunzip2(1 ) , xz(1 ) , u n x z (1 ) m a n pages


-

-
296 R H 1 24- R H E L 7-en-1-20140606

S-ar putea să vă placă și