리눅스 history에서 시간 보기

export HISTTIMEFORMAT="[%F %T]"

=> history에서 시간 보기

export HISTTIMEFORMAT=""

=> 원상복구 

 

부팅시 자동 적용되게 하려면 rc.local에 등록

centos7에서는 systemd로 부팅이 되면서 rc.local이 실행되지 않음

 

chmod u+x /etc/rc.d/rc.local

systemctl start rc.local

 

위 명령어를 수행하면 됨

 

리눅스 history 삭제

해당 유저의 홈폴더의 .bash_history 파일을 수정 또는 삭제

메모리에 기억되어있는 현재 세션의 명령어들은

unset HISTFILE 을 통해 삭제 가능

 

삭제방지를 방지 하려면 /etc/bashrc 이나 /etc/profile 밑에
declare -r HISTFILE 를 입력해준다.

 

 

 

 

출처 : https://www.lesstif.com/pages/viewpage.action?pageId=6979667

 

 

개요

yum 은 Yellowdog Updater Modified 의 약자로 대화형 패키지 관리 시스템이다. wikipedia 에 따르면 Duke 대학교의 물리학과에서 사용하는 Red Hat Linux 시스템의 관리를 편하게 하기 위해 만들어 졌다고 한다.

Slackware 때 사용하던 .tgz 패키지에 비해 rpm 은 의존성 관리와 버전 관리라는 장점이 있었지만 실제 rpm 으로 Linux 시스템을 관리할 경우 다음과 같은 문제가 있었다.

  • 특정 rpm 에 의존성 있는 패키지가 있을 경우 일일이 다운받아서 의존성 있는 rpm을 설치해야 함.
  • rpm 이 update 됐을 경우  update 됐다는 사실을 알기가 어려움(패키지마다 직접 확인 필요)

yum 은 central repository 를 통해 rpm 을 배포하고 의존성 관리를 하므로 손쉽게 패키지를 관리할수 있다.

 

주요 명령어와 옵션

yum 은 command 와 option 으로 구성되어 있다. yum --help 로 전체 명령어와 옵션을 확인할 수 있다.

많이 쓰이는 options 는 다음과 같다.

--enablerepo=[repo] 여러개의 yum repository가 있을 경우 사용할 repos 를 지정한다. * 같은 wildcard를 사용할 수 있다.
--disablerepo=[repo] 사용하지 않을 repos 를 지정한다. wildcard 사용 가능
--nogpgcheck GPG 서명검증을 사용하지 않는다. 해당 repos 의 공개키가 없어서 서명검증에 실패할 경우에 사용한다.
-d [debug level] debugging level을 지정한다. 0 - 10 까지 가능하며 숫자가 클수록 자세한 정보를 출력한다.
-y, --assumeyes yum 진행중 나오는 질문을 모두 yes 로 처리한다. 삭제할 경우에는 의존성있는 모든 패키지까지 삭제되므로 주의해야 한다.

 

install

패키지를 설치한다. 의존성있는 패키지까지 같이 설치해 준다.

update 

yum update httpd 와 같이 패키지명이 주어질 경우 해당 패키지의 새 버전이 있으면 update 한다. 패키지명이 없을 경우 전체 시스템에서 update 될 패키지를 확인후 update 한다. -y 옵션을 줄 경우 묻지 않고 업데이트하므로 주의해야 한다.

전체 update 수행시 배포본의 minor 버전이 변경될 수 있다. Ex: RHEL 6.1 -> 6.4

check-update

update 될 패키지의 목록을 출력한다.

clean

The following are the ways which you can invoke yum in clean mode. Note that "all files" in the commands below means "all files in currently enabled repositories". If you want to also clean any (temporarily) disabled repositories you need to use --enablerepo=’*’ option.


check

check Checks the local rpmdb and produces information on any problems it finds. You can pass the check command the arguments "dependencies" or "duplicates", to limit the checking that is performed (the default is "all" which does both).

The info command can also take ranges of transaction ids, of the form start..end, which will then display a merged history as if all the transactions in the range had happened at once.

Eg. "history info 1..4" will merge the first four transactions and display them as a single transaction. help Produces help, either for all commands or if given a command name then the help for that particular command.


repolist

현재 등록된 repossitory list 를 출력한다. repository 설정은 /etc/yum.repos.d/ 에서 확인할 수 있다.

yum search string

패키지명 및 description 에 "string" 들어간 패키지들을 출력한다. 

provides

yum search path-string

패키지에 포함된 파일명이 string 과 일치하는 패키지들을 출력한다.  예로 다음 명령어는 httpd.conf 란 파일이 있는 모든 패키지를 출력한다.

yum provides '*/httpd.conf'
 
389-admin-1.1.29-1.el6.i686 : 389 Administration Server (admin)
Repo        : epel
Matched from:
Filename    : /etc/dirsrv/admin-serv/httpd.conf
piranha-0.8.6-2.el6_4.1.x86_64 : Cluster administation tools
Repo        : updates
Matched from:
Filename    : /etc/sysconfig/ha/conf/httpd.conf

위와 같이 /etc/dirsrv/admin-serv/에 있는 httpd.conf 도 출력이 된다. /etc/httpd/ 밑에 httpd.conf 가 있는 패키지만 출력하고 싶다면 다음과 같이 경로를 지정한다.

yum provides '/etc/http*/httpd.conf'
 
httpd-2.2.15-28.el6.centos.x86_64 : Apache HTTP Server
Repo        : updates
Matched from:
Filename    : /etc/httpd/conf/httpd.conf

 

localinstall

yum repository 를 제공하지 않고 rpm 으로만 제공하는 패키지가 있을 경우 (Ex: MySQL) 유용한 명령어다.

rpm 을 로컬에 다운로드하고 yum localinstall 로 설치하면 된다.

rpm -ivh 로 설치할 수도 있지만 yum  으로 작업하면 transaction 기록이 남으므로 yum history 를 사용하여 rollback 이 가능하다.

rpm 제작사의 서명이 없어서 에러가 날수 있으므로 --nogpgcheck 옵션을 추가해야 할 경우도 있다.

yum plugin

yum 은 plugin 으로 기능을 확장할 수 있다. 사용가능한 전체 플러그인 목록은 "yum search yum-plugin" 명령어로 볼수 있다.

yum 을 실행하면 다음과 같이 현재 기동된 plugin 목록을 표시한다.

Loaded plugins: fastestmirror, presto, refresh-packagekit

 

유용한 플러그인은 다음과 같다.

downloadonly plugin

package 를 설치하지 않고 rpm 을 다운로드만 해주는 플러그인이다.

plugin 설치는 다음 yum 명령으로 설치하자.

yum install yum-downloadonly

 

download 시에는 --downloadonly 옵션을 붙여서 yum 을 실행하면 된다.

 

yum install postfix -y --downloadonly  

CentOS 7 에서는 yumdownloader 라는 별도의 명령어로 분리되었습니다

$ yumdownloader python --source

 

/var/cache/yum/ 에 다운로드 패키지 저장되니 아래처럼 하면 됨

yum install postfix -y --downloadonly --downloaddir=/opt
참고

 

verify plugin

설치된 패키지를 검증해 주는 플러그인이다.

다음 명령어로 httpd 패키지를 검증할 수 있다.

yum verify httpd

 

httpd 패키지의 설정파일의 수정 여부를 검증하려면 다음과 같이 수행한다.

yum verify --verify-filenames='/etc/httpd/*'  --verify-configuration-files=yes

특정 플러그인 disable

yum 실행시 --disableplugin 옵션으로 특정 플러그인의 사용을 잠시 중지할 수 있다. RHEL 의 경우 네트웍이 미구성되었거나 아직 subscription 을 등록 안 했을 경우 yum 실행시 RHN(RedHat Network) 에 연결하려고 하므로 DVD 나 ISO 로 local repository 를 만들어도 패키지를 설치할수 없다. 이럴 경우 다음과 같이 두 개의 plugin 을 잠시 중지시켜주면 RHN 연결과 상관없이 패키지를 설치할 수 있다.

yum --disableplugin=subscription-manager,rhnplugin install git -y

 

yum 설치 history 및 transaction 관리

패키지 설치, 변경, 삭제로 인해 내부 저장소가 변경되는 작업을 트랜잭션이라고 하며 RHEL6/CentOS 6 에 포함된 yum 부터는 트랜잭션 내역을 확인하고 rollback 을 할 수 있다. 

트랜잭션 목록 보기

yum history 를 옵션없이 실행하거나 옵션에 list 를 주면 최근 트랜잭션 목록을 볼 수 있다.

root@localhost:~:> yum history list
 
 
Loaded plugins: fastestmirror, security
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     8 | root <root>              | 2014-01-08 05:51 | Install        |    1  
     7 | root <root>              | 2014-01-08 04:23 | Reinstall      |    1  
     6 | root <root>              | 2014-01-08 03:18 | Reinstall      |    1  
     5 | root <root>              | 2014-01-07 06:44 | I, U           |    4  
     4 | root <root>              | 2014-01-02 05:32 | I, U           |    3  
     3 | root <root>              | 2014-01-01 03:48 | Install        |    4 EE
     2 | root <root>              | 2014-01-01 03:15 | I, U           |   28  
     1 | System <unset>           | 2013-12-15 03:43 | Install        |  534

 

모든 트랜잭션을 보려면 list 옵션뒤에 all 뒤에 키워드를 주면 된다.

root@localhost:~:> yum history list all

 

특정 범위내 트랜잭션만 보려면 "시작 트랜잭션 번호".."종료 트랜잭션 번호" 형식으로 입력하면 된다. 다음은 트랜잭션 번호가 30 에서 35인 목록을 출력한다.

yum history list 30..35
Loaded plugins: fastestmirror, replace
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    35 | root <root>              | 2014-01-12 16:53 | I, U           |    3 EE
    34 | root <root>              | 2014-01-12 14:05 | Install        |    1  
    33 | root <root>              | 2014-01-12 14:05 | Erase          |    2  
    32 | root <root>              | 2014-01-12 13:00 | Install        |    2  
    31 | root <root>              | 2014-01-12 13:00 | Erase          |    1  
    30 | root <root>              | 2014-01-02 10:18 | Install        |    5  
history list

 

트랜잭션에서 정보 추출

마지막 트랜잭션 정보 보기

root@localhost:~:> yum history info
 
Loaded plugins: fastestmirror, security
Transaction ID : 8
Begin time     : Wed Jan  8 05:51:29 2014
Begin rpmdb    : 541:b7c34882afac2a58081bb274b5aaf30c2f993335
End time       :            05:51:31 2014 (2 seconds)
End rpmdb      : 542:4124c5c718def4131929c4ca08df78611232aa42
User           : root <root>
Return-Code    : Success
Command Line   : install mc
Transaction performed with:
    Installed     rpm-4.8.0-37.el6.x86_64                       @anaconda-CentOS-201311272149.x86_64/6.5
    Installed     yum-3.2.29-43.el6.centos.noarch               @updates
    Installed     yum-plugin-fastestmirror-1.1.30-14.el6.noarch @anaconda-CentOS-201311272149.x86_64/6.5
Packages Altered:
    Install mc-1:4.7.0.2-3.el6.x86_64 @base
history info

 

ID 가 4 인 트랜잭션 정보 보기

root@localhost:~:> yum history info 4
 
Loaded plugins: fastestmirror, security
Transaction ID : 4
Begin time     : Thu Jan  2 05:32:21 2014
Begin rpmdb    : 539:85ca42f3d13cc18b6c4e179d32d564ba2ad47345
End time       :            05:32:30 2014 (9 seconds)
End rpmdb      : 540:a28a774308ff5f83227157e08f47bb2b3aa02618
User           : root <root>
Return-Code    : Success
Command Line   : localinstall git-1.8.3.1-1.sdl6.x86_64.rpm perl-Git-1.8.3.1-1.sdl6.noarch.rpm
Transaction performed with:
    Installed     rpm-4.8.0-37.el6.x86_64                       @anaconda-CentOS-201311272149.x86_64/6.5
    Installed     yum-3.2.29-43.el6.centos.noarch               @updates
    Installed     yum-plugin-fastestmirror-1.1.30-14.el6.noarch @anaconda-CentOS-201311272149.x86_64/6.5
Packages Altered:
    Updated     git-1.7.1-3.el6_4.1.x86_64          @anaconda-CentOS-201311272149.x86_64/6.5
    Update          1.8.3.1-1.sdl6.x86_64           @/git-1.8.3.1-1.sdl6.x86_64
    Updated     perl-Git-1.7.1-3.el6_4.1.noarch     @anaconda-CentOS-201311272149.x86_64/6.5
    Update               1.8.3.1-1.sdl6.noarch      @/perl-Git-1.8.3.1-1.sdl6.noarch
    Dep-Install perl-TermReadKey-2.30-13.el6.x86_64 @base
history info

 

트랜잭션 되돌리기

yum history undo ID 명령어로 특정 트랜잭션을 되돌릴 수 있다. (ID는 트랜잭션 번호이다)

예로 다음과 같이 트랜잭션 8에서 mc 라는 패키지를 설치했을 경우

root@localhost:~:> yum history list
 
Loaded plugins: fastestmirror, security
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     8 | root <root>              | 2014-01-08 05:51 | Install        |    1  
     7 | root <root>              | 2014-01-08 04:23 | Reinstall      |    1  
     6 | root <root>              | 2014-01-08 03:18 | Reinstall      |    1  
     5 | root <root>              | 2014-01-07 06:44 | I, U           |    4  
     4 | root <root>              | 2014-01-02 05:32 | I, U           |    3  
     3 | root <root>              | 2014-01-01 03:48 | Install        |    4 EE
     2 | root <root>              | 2014-01-01 03:15 | I, U           |   28  
     1 | System <unset>           | 2013-12-15 03:43 | Install        |  534  
history list

yum history undo 8 을 실행하면 8번 트랜잭션에 대해 undo 를 수행한다. undo 의 결과는 해당 트랜잭션이 무엇이었는지에 따라 다르다. 설치였으면 undo 는 삭제가 되고 삭제였다면 undo 는 설치가 된다.

예로 트랜잭션 8번에서 mc 라는 패키지를 설치했으면 undo 8의 결과는 mc 패키지의 삭제가 된다

transaction 8 번 되돌리기
root@localhost:~:>  yum history undo 8
 
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: data.nicehosting.co.kr
 * extras: data.nicehosting.co.kr
 * updates: data.nicehosting.co.kr
Undoing transaction 8, from Wed Jan  8 05:51:29 2014
    Install mc-1:4.7.0.2-3.el6.x86_64 @base
Resolving Dependencies
--> Running transaction check
---> Package mc.x86_64 1:4.7.0.2-3.el6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================
 Package              Arch                     Version                             Repository               Size
=================================================================================================================
Removing:
 mc                   x86_64                   1:4.7.0.2-3.el6                     @base                   5.4 M
Transaction Summary
=================================================================================================================
Remove        1 Package(s)
Installed size: 5.4 M
Is this ok [y/N]: y

 

undo의 결과로 다음과 같이 transaction 9번이 생겼고 Action 은 Erase 가 된다.

root@localhost:~:> yum history list  
 
Loaded plugins: fastestmirror, security
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     9 | root <root>              | 2014-01-08 05:58 | Erase          |    1  
     8 | root <root>              | 2014-01-08 05:51 | Install        |    1  
     7 | root <root>              | 2014-01-08 04:23 | Reinstall      |    1  
     6 | root <root>              | 2014-01-08 03:18 | Reinstall      |    1  
     5 | root <root>              | 2014-01-07 06:44 | I, U           |    4  
     4 | root <root>              | 2014-01-02 05:32 | I, U           |    3  
     3 | root <root>              | 2014-01-01 03:48 | Install        |    4 EE
     2 | root <root>              | 2014-01-01 03:15 | I, U           |   28  
     1 | System <unset>           | 2013-12-15 03:43 | Install        |  534  
history list

 

모든 history 를 삭제하는 위험한 명령어이다. 특별한 이유가 없다면 실행하지 않는다.

yum history new

 

같이 보기

이전 버전에선 /etc/inittab 에서 아래 id:5:initdefault: 부분의 숫자를 변경해주면 변경가능

 

[root@python ~]# vi /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
~
~

 

하지만 7버전대 와서는 init을 쓰지 않게 되면서 파일 내용이 아래와 같이 변경

결론은 아래 파일을 보고 systemctl 명령어로 runlevel을 변경하면 됨

# systemctl get-default   // 현재 runlevel을 보여주기

# systemctl set-default multi-user.target   // 멀티유저(runlevel 3)으로 변경

# systemctl set-default graphical.target   // 그래피컬(runlevel 5)로 변경

 

 

[root@localhost etc]# cat inittab
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
#

 

 

# find . -type f -exec du -s {} \; | sort -n | tail -1
현재 폴더 이하에서 가장 큰 파일 표시

 

# find . -type f -exec perl -pi -e 's|old|new|g' {} \; 2> /dev/null     

현재 폴더 이하에서 가장 old 문자열을 가진 파일을 검색 후 new로 치환

 

# find . -exec grep -l "문자열" {} \; 2> /dev/null     

문자열 검색

 

# find . -ctime -30 -name "*" -exec rm -rf {} \;

30일 이상된 파일 삭제

리눅스 서버의 경우 랜카드가 교체될 경우(Mac주소가 변경시)

ethX의 번호가 다음 번호 변경되는데 특히 가상머신의 경우 OS이미지를 다른 가상머신에서 사용시 기존 가상머신의

MAC주소와 달라 eth0이던게 eth1로 변경됨.. 물론 ifcfg-eth0을 eth1로 변경해도 됨..

 

이 경우는 아래와 같이 기존의 네트워크 카드가 /etc/udev/rules.d/70-persistent-net.rules 에 정의 되어 있어 생기는 현상

아래의 경우는 실제 디바이스는 eth2 이지만 기존에 정의된 eth0과 eth1로 인해 eth2까지 밀린 상황

해결 방법은 파일을 수정(eth1, eth2 내용을 삭제 후 eth0의 mac주소값을 52:54:00:a6:f8:42에서 52:54:00:21:E9:C3 으로 변경 또는

삭제 후 재부팅을 한다. 물론 ifcfg-eth0 파일이 있어야 네트워크를 사용가능함..

 

[root@localhost /]# ifconfig -a
eth2      Link encap:Ethernet  HWaddr 52:54:00:21:E9:C3
          inet addr:192.168.10.108  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::5054:ff:fe21:e9c3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11724 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2465 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1016787 (992.9 KiB)  TX bytes:437308 (427.0 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

 

[root@localhost /]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

 

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:a6:f8:42", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

 

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:5b:a3:8c", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

 

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:21:e9:c3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2" 

 

 

[root@localhost /]# rm /etc/udev/rules.d/70-persistent-net.rules
rm: remove regular file `/etc/udev/rules.d/70-persistent-net.rules'? y
[root@localhost /]# ls /etc/udev/rules.d/
60-fprint-autosuspend.rules  60-pcmcia.rules  60-raw.rules  70-persistent-cd.rules  90-alsa.rules  90-hal.rules  98-kexec.rules

 

[root@localhost /]# mv /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-eth0

[root@localhost /]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth2    // eth0으로 변경
#HWADDR=52:54:00:A6:F8:42
TYPE=Ethernet
#UUID=803a97dd-c983-439e-8d0f-21f85f309062
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

 

[root@localhost /]# reboot

 

[root@localhost /]# ls /etc/udev/rules.d/
60-fprint-autosuspend.rules  60-pcmcia.rules  60-raw.rules  70-persistent-cd.rules  70-persistent-net.rules  90-alsa.rules  90-hal.rules  98-kexec.rules 

// 재부팅 후 70-persistent-net.rules 생성

 

[root@localhost /]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:21:e9:c3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

 

레드햇 계열의 리눅스는 7버전으로 넘어 오면서 많은점이 바뀌었는데 네트워크 디바이스 이름이 틀림

기존 버전과 같이 ifcfg-eth0, eth1..... 과 같은 형태가 아닌 ifcfg-enpXX 형식인데 BIOS에서 디바이스를 보는 형식으로 바뀌었음

예를 들면 아래와 같이 enp0s25와 enp4s0의 디바이스가 있는 경우 enp0s25는 pci 0번 버스의 25번째 슬롯(00:19:0 - 16진수)이며

enp4s0은 pci 4번 버스에 0번 슬롯(04:00:0 - 16진수)을 나타내는 형식

 

[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-* -alrt
-rw-r--r--. 1 root root 254 Sep 16 20:51 /etc/sysconfig/network-scripts/ifcfg-lo
-rw-r--r--. 1 root root  39 Jan  4 16:33 /etc/sysconfig/network-scripts/ifcfg-enp0s25
-rw-r--r--. 1 root root 288 Jan  4 23:00 /etc/sysconfig/network-scripts/ifcfg-enp4s0

[root@localhost ~]# lspci | grep -i ether
00:19.0 Ethernet controller: Intel Corporation Ethernet Connection I217-LM (rev 05)
04:00.0 Ethernet controller: Intel Corporation I210 Gigabit Network Connection (rev 03)

 

다만 기존의 eth0, eth1으로 변경 하기 원한다면 /etc/default/grub 파일을 열어 GRUB_CMDLINE_LINUX 항목에 net.ifnames=0 biosdevname=0 항목을 추가후 저장..

grub2-mkconfig -o /boot/grub2/grub.cfg 를 통해 grub를 업데이트 하여 아래와 같이 done이 나오면 완료

 

[root@localhost ~]# vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/swap ...(생략)... net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"

 

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64

(생략)

Found initrd image: /boot/initramfs-0-rescue-2a41b98f9b9f48428ee53544d9cf87ef.img
done
[root@localhost ~]#

 

이후 재부팅을 완료하면 네이밍 형식은 바뀌지만 /etc/sysconfig/network-scripts/ 밑에는 기존의 enp형식으로 만 있으면 네트워크를 사용 할수 없어

eth형식의 파일이 필요 하기 때문에 아래와 같이 파일의 이름을 바꿔주고 실제 그 파일 내의 Device 이름도 변경

이후 재부팅하면 모두 적용 되며 2개 이상의 device의 경우는 /etc/udev/rules.d/70-persistent-net.rules 파일을 수정해야 함

 

[root@localhost ~]# mv /etc/sysconfig/network-scripts/ifcfg-enp0s25 /etc/sysconfig/network-scripts/ifcfg-eth0

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
HWADDR=D0:50:99:51:91:19
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s25  // => eth0으로 변경
UUID=466db8ad-a566-4b5d-878c-ab442505c1d3
ONBOOT=no

[출처] 간단하지만 강력한 파일 편집기 'sed'|작성자 신바람형제들

1. sed란 무엇인가?

 


sed는 비 대화형 모드의 줄 단위 편집기라고 합니다. 

vi 편집기처럼 직접 파일을 열어 고치지 않고 커맨드 창 또는 스크립트에서 동작을 하여 원하는 부분만 변경해준다는 특징이 있습니다.


2. sed의 특징


sed는 쉘 또는 스크립트에서 파이프(|)와 같이 사용될 수 있는 명령어입니다.

그리고 기본적으로 정규표현식이 사용가능하기 때문에 정규표현식을 알면 더 고급지게 sed를 이용할 수 있습니다.

주의할 점은 정규표현식을 사용하기 때문에 특수문자 앞에 역 슬래시(\,\)를 붙여주어야 합니다. \를 쓰면 리눅스에서는 역슬래시로 받아들입니다.

예) sed 's/\$man/man/g' test.txt


3. sed 옵션


옵션은 sed -e 의 형식으로 사용됩니다.


e: sed를 사용하였을 때 출력되는 값을 보여줍니다. 이 옵션은 기본값으로 굳이 안 써도 되지만 다중 명령어를 쓸 때는 반드시 써야 합니다.
예) sed /man/p -e /girl/p 파일명: man과 girl이 들어있는 줄을 한번 더 출력


i: 변경되는 값을 실제로 파일에 저장하는 옵션입니다. 이 옵션은 출력되는 값이 없이 바로 실제 파일에 적용되는 것이 특징입니다.


n: 특정 값이 들어간 줄만 출력해주는 기능입니다. 주로 p 명령어와 사용된다고 합니다.


f: 스크립트를 파일로부터 읽어들이며 명령어를 지정하는 명령어라고 하는데 저는 거의 사용하지 않습니다.


4. sed 명령어


d: 줄 삭제 명령어

a\: 해당 값이 있는 줄 다음에 입력. 그냥 밑에 줄 하나 삽입되는 정도로 알고 있으면 됩니다.

i\: 줄 앞에 첨가 명령어

c\: 해당 줄을 변경하는 명령어

g: 한 줄에 해당하는 값이 여러개 있을 경우에 모두 변경하는 명령어. 이 명령어를 해당 줄의 제일 앞에 내용만 변경됩니다.

p: 조건에 부합하는 라인을 출력하는 명령어

s/orgin/change/: 앞에 것을 뒤에 것으로 변경하는 명령어


5. sed 사용방법


기본적으로 p,d,s 옵션들을 가장 많이 사용한다고 알려져있습니다. 

세가지만 예시로 들겠습니다.

궁금하신 부분은 댓글로 남겨주세요~!


기능: 출력

sed p 파일명: 파일 전체 출력 (cat과 같은 기능)

sed 3p 파일명: 3번째 줄 한번 더 출력

sed 3,4p 파일명: 3,4번째 줄 한번 더 출력

sed /man/p 파일명: man이 포함된 줄 한번 더 출력

sed -n 3p 파일명: 3번째 줄만 출력(n이 붙으면 조건에 해당하는 줄만 출력됨)


기능: 삭제

sed 3d 파일명: 3번째 줄 삭제하고 나머지 줄 출력

sed /man/d 파일명: man이 포함된 줄 삭제 나머지 줄 출력


s

기능: 치환

sed 's/man/girl/g' 파일명: man을 girl로 치환

sed -n 's/man/girl/p' 파일명: man을 girl로 치환하고 치환된 줄을 출력


6. 조금 더 유용한 sed 이용방법


공백 줄 제거하기

sed '/^$/d' 파일명


모든 줄마다 공백을 추가하기

sed 'a\\' 파일명


주석이 처리된 줄 모두 삭제

sed '/^#/d' 파일명


이 외에 리눅스 세팅 시에 스크립트에 등록하여 특정 줄을 추가하는 등의 역할을 수행하게 할 수도 있습니다.

sed -i "/HISTSIZE=1000/a\HISTTIMEFORMAT='%F %T ---'" /etc/profile 

위의 사용방법은 history 결과값에 날짜와 시간을 표현하게 해주는 방법입니다.


sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

혹은 selinux를 자동으로 꺼주는 스크립트를 만들 수도 있구요.


잘 쓰면 정말 유용하게 사용할 수 있는 sed, 간과하지 말고 자주자주 사용하도록 합시다~!

 

+ Recent posts