컴퓨터에서 디스크의 의미는 매우 중요합니다. 사람의 데이터를 영구적으로 보관해야 할 의무를 가지 때문이지요. 이러한 디스크에 문제가 발생한다면 데이터를 영구적으로 잃을 수도 있고 오늘과 같이 IT 를 기반으로 사회가 움직이는 마당에 그러한 일이 발생한다면 큰 금전적인 손실을 입을 수도 있습니다. 이렇게 중요한 디스크의 문제나 오류를 차단하기 위해서는 주기적으로 점검을 해야할 필요가 있는데, 리눅스 시스템에서는 이러한 유용한 도구를 제공 합니다. smartctl smartctl 도구는 S.M.A.R.T. (Self-Monitoring, Analysis, and Reporting Technology) 기능이 탑재된 하드디스크를 점검하는 도구 입니다. 사실상 S.M.A.R.T 의 기능을 이용하는 도구이다보니 이 […]
iptable 의 hashlimit 를 이용한 접속 제한
보통 DDOS 공격과 같은 경우에 초당 몇 십개에서 몇백번건의 접속을 시도 합니다. 이러한 초당 수백건의 접속을 이용해서 iptables 의 hashlimit 를 이용한 접속 제한을 할 수 있습니다.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
hashlimit match options --hashlimit-upto max average match rate [Packets per second unless followed by /sec /minute /hour /day postfixes] –hashlimit-above min average match rate –hashlimit-mode mode is a comma-separated list of dstip,srcip,dstport,srcport (or none) –hashlimit-srcmask source address grouping prefix length –hashlimit-dstmask destination address grouping prefix length –hashlimit-name name for /proc/net/ipt_hashlimit –hashlimit-burst number to match in a burst, default 5 –hashlimit-htable-size number of hashtable buckets –hashlimit-htable-max number of hashtable entries –hashlimit-htable-gcinterval interval between garbage collection runs –hashlimit-htable-expire after which time are idle entries expired? |
예를들어 초당 20번 이상 접속을 시도하는 것을 차단하고 싶다면 다음과 같이 지정하면 됩니다.
|
1 |
-m hashlimit --hashlimit-name dnsudplimit --hashlimit-above 20/second --hashlimit-mode srcip --hashlimit-burst 100 --hashlimit-srcmask 24 --hashlimit-htable-expire 3600 -j DROP |
이 차단은 약 1시간 동안 유지됩니다.
CentOS IPv6 비활성화
IPv4 의 부족분을 대체하기 위해서 IPv6 가 개발되었지만 아직까지 사용빈도가 높지않아 리눅스 IPv6 비활성화 시켜서 자원을 아낄 수 있습니다. 기본적으로 CentOS 6, 7 에서는 IPv6 가 활성화 되어 있습니다.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 소켓 리스닝 상태 netstat -lpn Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1550/rpcbind tcp 0 0 0.0.0.0:39698 0.0.0.0:* LISTEN 1568/rpc.statd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1622/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1698/master tcp 0 0 :::111 :::* LISTEN 1550/rpcbind tcp 0 0 :::22 :::* LISTEN 1622/sshd tcp 0 0 ::1:25 :::* LISTEN 1698/master tcp 0 0 :::57468 :::* LISTEN 1568/rpc.statd udp 0 0 0.0.0.0:877 0.0.0.0:* 1550/rpcbind udp 0 0 0.0.0.0:111 0.0.0.0:* 1550/rpcbind udp 0 0 0.0.0.0:896 0.0.0.0:* 1568/rpc.statd udp 0 0 0.0.0.0:46387 0.0.0.0:* 1568/rpc.statd udp 0 0 0.0.0.0:68 0.0.0.0:* 1462/dhclient udp 0 0 :::877 :::* 1550/rpcbind udp 0 0 :::111 :::* 1550/rpcbind udp 0 0 :::46198 :::* 1568/rpc.statd # 커널 모듈 상태 lsmod | grep ipv6 nf_conntrack_ipv6 8337 2 nf_defrag_ipv6 11156 1 nf_conntrack_ipv6 nf_conntrack 79758 7 xt_conntrack,ipt_MASQUERADE,iptable_nat,nf_nat,nf_conntrack_ipv4,nf_conntrack_ipv6,xt_state ipv6 318183 153 ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6 |
위와같이 IPv6 가 사용 됩니다. CentOS 6 1. IPv6 커널 모듈 비활성화 다음과 같이 IPv6 커널 모듈이 로딩되지 않도록 해줍니다.
|
1 |
echo "install ipv6 /bin/true" > /etc/modprobe.d/disable_ipv6.conf |
2. 커널 파라메터 추가 다음과 같이 IPv6 커널 파라메터를 추가해 줍니다.
|
1 2 |
echo "net.ipv6.conf.default.disable_ipv6=1" >> /etc/sysctl.conf echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf |
이제 재부팅을 해주면 IPv6 가 비활성화 됩니다. CentOS 7 1. Grub2 IPv6 비활성화 옵션 추가
|
1 2 3 4 5 6 7 8 |
# vim /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="ipv6.disable=1 vconsole.font=latarcyrheb-sun16 vconsole.keymap=ko crashkernel=auto rhgb quiet" GRUB_DISABLE_RECOVERY="true" |
이와같이 […]
Man 페이지 텍스트, PDF로 저장
Man 페이지 텍스트 파일로 저장.
|
1 |
man grep | col -b > grep.man |
Man 페이지 PDF 파일로 저장.
|
1 |
man -t grep | ps2pdf - > grep.pdf |
Man 페이지 HTML 파일로 저장. 먼저 패키지를 설치해야 합니다.
|
1 |
yum install man2html-core.x86_64 netpbm-progs.x86_64 psutils.x86_64 |
그리고 다음과 같이 해줍니다.
|
1 |
zcat /usr/share/man/man1/man.1.gz | groff -mandoc -Thtml > a.html |
Man Page 컬러로 보기
리눅스의 Man Page 는 컬러가 아닙니다. 흑백으로만 나옵니다. 중요한 내용에 컬러를 입히면 눈에 잘 들어올텐데, 이걸 가능하게 하는 방법입니다.
|
1 2 3 4 5 6 7 8 9 10 11 12 |
]$ vim .bashrc man() { env \ LESS_TERMCAP_mb=$(printf "\e[1;31m") \ LESS_TERMCAP_md=$(printf "\e[1;31m") \ LESS_TERMCAP_me=$(printf "\e[0m") \ LESS_TERMCAP_se=$(printf "\e[0m") \ LESS_TERMCAP_so=$(printf "\e[1;44;33m") \ LESS_TERMCAP_ue=$(printf "\e[0m") \ LESS_TERMCAP_us=$(printf "\e[1;32m") \ man "$@" } |
‘source ~/.bashrc’ 를 해주면 바로 적용 됩니다. 그런데, xterm 을 사용하고 있다면 다음과 같이 .Xdefaults 에 다음과 같이 해줍니다.
|
1 2 3 4 |
*VT100.colorBDMode: true *VT100.colorBD: red *VT100.colorULMode: true *VT100.colorUL: cyan |
그리고 다음과 같이 적용을 해줍니다.
|
1 |
]$ xrdb -load ~/.Xdefaults |
출처: http://www.cyberciti.biz/faq/linux-unix-colored-man-pages-with-less-command/
Bash 패스워드 생성기.
쉘 스크립트에서 간단하게 패스워드를 생성할 수 있습니다.
|
1 2 3 4 5 6 7 8 |
]$ vim .bashrc genpasswd() { local l=$1 [ "$l" == "" ] && l=8 tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs } ]$ source .bashrc |
사용법은 다음과 같습니다.
|
1 |
genpasswd [자릿수] |