Documente Academic
Documente Profesional
Documente Cultură
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.
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 -
-
-
Quiz
-
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.
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
'
� -
-- - �
IP address : 10 . 4 . 5 . 6/24
-- - - - - -
Gateway : 10 . 4 . 6 . 1
-
-
'- - ----- - -- -
-
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
-
Sol ution
-
Solution
-
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 : 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
-
-
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 .
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
-
Troubleshooting routing -
-
-
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.
-
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.
[student@desktopX
State Recv-Q Send-Q Local Address : Port Peer Address. :. Port
- -)$ ss - ta
LISTEN 0 128
LISTEN 0 100 G 121 . 0 . 0 . 1 : smtp •.*
-
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.
-
-
-
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.
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
-
-
-
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.
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
-
-
D 2. D i s p l a y the stat i s t i cs for the ethO i nte rfa ce.
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 .
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 ] $ t racepat h
-
[student@serverx -]$ s s - lt
-
--
-
-
-
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.
ipv4 . routes :
=
ipv4 . ignore-auto-dns : no
ipv4 . dhcp-client-id :
-
-
-
I ...
-
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
-
=
= = :
-
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 .
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 -
-
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 .
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 . -
-
272 R H 1 24- R H E L7-e n-1-20140606
-
-
-
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.
type <type>
ifname <interface name> I " * "
[con- name <connection name>
-
-
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.
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.
-
-
2. Specify a D N S server.
J
-
" static " ipv4 . dn s 172 . 25 . X . 254
i __ _ _
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- ------- ---- --��-- --------'
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 -
-
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 -
-
-
S u m m a ry of nmcli com m a n d s
-
k?S-J
< �'
Note
-
-
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
-
-
Guide d exercise
-
Outcomes: -
R e s e t yo u r serverX system.
D 1 .1 . S h ow a l l connections.
connection . read-only : no
connection . permissions :
IP4 . ADDRESS [1] : ip 172 . 25 .X . 11/24, gw
-
[student@serverX -]$
-
-
-
G u i d e d exercise
-
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.
-
-
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
-
[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.
-
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.
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 .
27 8 RH124- R H E L 7 - e n -1-20140606 -
-
-
-
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.
-
( 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
-
-
Guide d exercise -
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 .
-
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
-- - -· --� - � - ------ ·
[ root@serverx
I - ] # nmcli· c o n u p " s y s te m e t h a "
_______________ _____ ______ ___.
-
[ root@desktopX - ] #
-
[ 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
______ .
-
-
G u i d e d exercise
-
[ root@desktopX
I
-
� ] # nmcli con up " System e t h 0 "
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
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
-
-
-
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 .
[ 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.
Confi g u r i n g n a m e reso l ut i o n
-
Generated by NetworkManager
domain example . com
#
I [ root@desktopX
[ root@desktopX
-
.-- ������ .������
!
I [ root@desktopX
-] # nmcli con down ID
[ root@desktopX
;;�1"8. B B. B
j
- -] # nmcli con up 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
-
[ root@desktopx
-
-
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.
-
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 References
"'· -�·
-
-
-
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.
[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.
Chassis : n/a
Machine I D : 9f6fb63045a845d79e5e870b914c61c9
Boot ID : d4ec3a2e8d3c48749aa82738c0ea946a
-
�������
-
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.
-
I [student@serverx -]$ s u d o h o s t namec tl set - host name se rve rX . example . com
I
[student@serverx -]$
-
L
serverX. example . com
cat /etc/host name
-
-
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
-
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
[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.
-
L___·����--'
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 -
-
286 R H 1 24- R H EL 7-en-1-20140606
-
-
G u i d e d exercise
-
D 4.3. Look up the I P a d d ress of the c l ass.
-
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
-
-
-
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 .
-
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 .
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
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:
5. Re boot t h e system, then run lab ne two r k g rade to verify sett i ngs.
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 .
-
-
red h at ®
®
TRAINING
C H A PT E R 1 2
Overview:
R H 1 24 - R H E L7 -en-1-20140606 2 91
-
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 .
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 .
· c (create a n a rc h i ve)
• x (extract an a rc h ive)
-
Co m m o n l y used options a re :
-
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.
-
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.
-
-
-
[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 .
-
I mportant
-
-
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 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:
. ..... >., -
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.
-
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:
-
-
_J
I [ root@serverX -]$ �J f -�r o�t / sshconfig . t a r . xz / e t c / s s h
-
tar _
_
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
!'----------- ----- -
-
I
[ root@serverX -]$ cd /tmp/sshbackup
!
-
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 .
-
-
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. -
R References -
-
296 R H 1 24- R H E L 7-en-1-20140606