간단한 명령어로 확인이 가능하다.

LONG 때문에 TCP 통신하는 경우 32/64bit 간에 오류가

나게 되는데 아래와 같이 하면 쉽게 확인이 된다.

 

출처 : http://baljack.tistory.com/6

 

LINUX
# getconf LONG_BIT

HP UX

11.xx 일 경우
# getconf KERNEL_BITS
64

10.xx 일 경우
# getconf LONG_MAX
2147483647
(64비트임)로 확인할 수 있습니다

AIX

현재 load된 kernel 이 32-bit 혹은 64-bit 인지 확인하는 명령어
# bootinfo -K
32

사용중인 machine이 32-bit 혹은 64-bit 인지 확인하는 명령어
# bootinfo -y
32


SOLARIS

# isainfo -kv
64-bit sparcv9 kernel modules
현재 이 시스템은 64bit 커널을 가지고 운영을 하는 시스템 이다.

# isainfo -kv
32-bit sparcv kernel modules
이 시스템은 32bit 커널을 가지고 운영을 하는 시스템이다.

# isainfo -v
64-bit sparcv9 applications

32-bit sparc applications
"-v"만 했을 경우 이 시스템에서는 32bit / 64bit 체계의 프로그램을 사용할 수 있다.

# isainfo -v
32-bit sparc applications
이 시스템은 32bit 체계의 프로그램만 구성하여 사용할 수 있다.

 

 

반응형

출처 : http://www.3rabbitz.com/f01c33e7d8367da2#857542b4ddd63403#

2.1설정하기에 앞서

CentOS에서 어떠한 작업을 하게된다면 다음의 내용은 반드시 알고 있어야 한다.

설정파일 텍스트(text)파일로 저장되어 있기 때문에 파일을 복사, 수정, 저장 등을 할 수 있어야 한다. 따라서 다음 명령어들의 기본사용법을 알아두어야 한다.

vi - Unix 및 Linux에 쓰이는 표준 편집기

http://www.cals.wisc.edu/calslab/pdf/Vi.pdf

명령 모드와 삽입 모드

대부분의 워드 프로세싱 소프트웨어와는 달리, vi 편집기는 두 가지 모드를 사용합니다

  • (또한 편집 모드라고도 함) 명령 모드
  • 모드를 삽입

당신은 명령 모드에서 입력 명령

  • 텍스트를 변경할 수 있도록 - 타이핑 오류를 수정 추가하거나 라인을 빼기 등
  • 일반적으로 화면에 인쇄되지 않습니다
  • 일반적으로 그들이 대문자와 소문자 사이에 차이가있다는 의미 ", 대소문자를 구분합니다"입니다 그들을 입력한 후 반환 키를 요구하지 않습니다.

파일에 텍스트를 추가하려면, 삽입 모드에서 이동 i를 눌러, vi 명령을 사용합니다.

당신은 삽입 모드에서 입력 무엇 :

  • 이 링크는 편집중인 파일의 일부가
  • 당신은 텍스트의 새 줄을 시작하려면 RETURN 키를 눌러해야합니다.

명령 모드로 돌아가려면 Esc 키를 누릅니다.

  • h , moves cursor left
  • j , moves cursor down
  • k , moves cursor up
  • l , moves cursor right
  • x , delete character
  • ##x , delete ## characters
  • dw , delete word
  • dd , delete line
  • p , put last deletion after cursor
  • u , undo last change
  • i , turn on insert mode (hit the esc key twice to stop)
  • :w ,write to the file already named
  • :q , quit editing
  • :wq , write file and quit
  • :q! , quit without saving file
  • ctrl f , move forward one page
  • ctrl b , move backward one page
  • :/text , will search for next occurance of 'text' (hitting n will find next occurence)
  • :?text ,search backward for first occurrence of text
  • G , go to end of file
  • 1G , go to first line of file
  • set nu , to set line number
  • :w filename , write to the file named filename
  • yy , yank line into buffer
  • ##yy , yank ## lines into general buffer
  • CONTROL-G print information about file: name, current line number
  • :%s/pattern/text/ substitute first occurrence of pattern on each line with text
  • :%s/pattern/text/g substitute every occurrence of pattern with text
  • p , put contents of general buffer after current line
  • P , put contents of general buffer before current line
  • :g/pattern/d delete every line containing pattern

2.2시스템 업데이트

네트워크가 설정되고 인터넷에 연결되고 나서, 가장 먼저 할 일은 바로 업데이트 작업이다. 최초 배포판이후에 알려진 보안, 버그 업데이트들을 시스템에 적용하는 것이다. 이 작업을 하기 전에 몇가지 참고할 사항을 설명한다.

느린 YUM Public mirror를 제외(exclude) 하는 방법

CentOS의 업데이트 서버 한국 미러서버에 mirror.khlug.org, data.nicehosting.co.kr가 있는데, 속도 제한(QoS)가 설정되어 있는지 1kb/sec의 속도가 나올정도로 상당히 느리다. 이로 인해 업데이트 작업이 엄청나게 오래 걸리게 되므로, 위 서버들은 예외되도록 설정하자.

[root@test1 ~]# cat /etc/yum/pluginconf.d/fastestmirror.conf
[main]
enabled=1
verbose=0
always_print_best_host = true
socket_timeout=3
# Relative paths are relative to the cachedir (and so works for users as well
# as root).
hostfilepath=timedhosts.txt
maxhostfileage=10
maxthreads=15
exclude=mirror.khlug.org, data.nicehosting.co.kr

이 팁은 커피닉스 IRC채널에서 티니님이 알려주셔서 알게되었다.

2.3보안 관련 설정 중단

정보보호가 강조되는 시대에, 관련 기능을 중단시킨다는 것은 참으로 위험한 일이다. 그러나 본 책의 목적이 일단 LAMP서버 설정에 있으므로, SELinux나 iptables같은 보안 관련 기능은 추후에 다루기로 한다. 일단 LAMP서버 구성에 불편함이 없도록 보안관려된 서비스는 중단하기로 한다.

SELinux

상태 확인

[root@gserver1 ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: permissive
Policy version: 24
Policy from config file: targeted

SELinux는 설정을 변경하고 재시작해야 적용된다.

[root@test1 ~]# cat /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

재부팅 한 후에 확인한다.

[root@gserver1 ~]# sestatus
SELinux status: disabled

iptables(방화벽) 중단

방화벽 기능을 사용하지 않을 경우

chkconfig iptables off
chkconfig ip6tables off

확인

[root@gserver1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

2.4불필요한 서비스 중단

불필요한 서비스를 중단하므로써, 메모리도 절약하고, 보안 취약성도 낮추는등의 장점이 있다. 커널 모듈의 취약점이 발표되는 경우도 종종 있다.

iscsi나 FCoe와 같은 IP기반의 스토리지를 쓰지 않을 경우

chkconfig iscsi off
chkconfig iscsid off
chkconfig fcoe off
chkconfig lldpad off

NFS를 사용하지 않는 경우

chkconfig nfslock off
chkconfig rpcbind off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig netfs off

[root@gserver1 ~]# chkconfig --list | grep "3:on"
auditd         0:off        1:off        2:on        3:on        4:on        5:on        6:off
lvm2-monitor         0:off        1:on        2:on        3:on        4:on        5:on        6:off
network         0:off        1:off        2:on        3:on        4:on        5:on        6:off
rsyslog         0:off        1:off        2:on        3:on        4:on        5:on        6:off
sshd         0:off        1:off        2:on        3:on        4:on        5:on        6:off
udev-post         0:off        1:on        2:on        3:on        4:on        5:on        6:off

2.5시간서버 설정

서버의 시간을 표준시에 동기화시킨다. 정확한 시간은 서버 장애나 보안사고 발생시, 아주 중요하게 작용하므로 반드시 정확한 시간을 서버에 설정한다.

NTP 설정

[root@gserver1 ~]# yum install ntp
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
* base: ftp.daum.net
* extras: ftp.daum.net
* updates: ftp.daum.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.4p8-2.el6.centos will be installed
--> Processing Dependency: ntpdate = 4.2.4p8-2.el6.centos for package: ntp-4.2.4p8-2.el6.centos.x86_64
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.4p8-2.el6.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================
Package Arch Version Repository Size
====================================================================================
Installing:
ntp x86_64 4.2.4p8-2.el6.centos base 444 k
Installing for dependencies:
ntpdate x86_64 4.2.4p8-2.el6.centos base 58 k

Transaction Summary
====================================================================================Install 2 Package(s)

Total download size: 501 k
Installed size: 1.2 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 501 k
(1/2): ntp-4.2.4p8-2.el6.centos.x86_64.rpm | 444 kB 00:00
(2/2): ntpdate-4.2.4p8-2.el6.centos.x86_64.rpm | 58 kB 00:00
------------------------------------------------------------------------------------Total 619 kB/s | 501 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : ntpdate-4.2.4p8-2.el6.centos.x86_64 1/2
Installing : ntp-4.2.4p8-2.el6.centos.x86_64 2/2

Installed:
ntp.x86_64 0:4.2.4p8-2.el6.centos

Dependency Installed:
ntpdate.x86_64 0:4.2.4p8-2.el6.centos

Complete!

[root@gserver1 ~]# cat /etc/ntp.conf
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
server kr.pool.ntp.org
server ntp.postech.ac.kr
server ntp.xbsd.kr

[root@gserver1 ~]# ntpdate kr.pool.ntp.org
21 Dec 16:58:38 ntpdate[1019]: step time server 222.239.76.224 offset -32.764434 sec

[root@gserver1 ~]# service ntpd start
Starting ntpd: [ OK ]

[root@gserver1 ~]# chkconfig ntpd on

[root@gserver1 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
118.219.234.251 216.171.124.36 2 u 15 64 1 14.547 -15.373 0.004
gps-ntp.postech .GPS. 1 u 14 64 1 11.879 -3.321 0.004
121.182.147.191 .GPS. 1 u 13 64 1 10.341 -3.890 0.004

5-10분 정도 후에 아래와 같이 *, +가 보이면 NTP서버와 시간이 동기화 되는 것이다.

[root@gserver1 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
118.219.234.251 216.171.124.36 2 u 18 64 17 10.310 -34.335 14.195
*ntp-server.post .GPS. 1 u 17 64 17 12.002 -25.004 15.716
+121.182.147.191 .GPS. 1 u 14 64 17 14.105 -26.837 17.016

2.6SSH보안 및 sudo설정

많은 방법이 있겠지만 최소한 다음 정도는 해주면 될것이다.

참고자료 :

http://fedorasolved.org/post-install-solutions/securing-ssh

  • SSH의 기폰 포트인 22번에서 다른 포트로 변경한다.
  • SSH 서버설정에서 원격(Remote)에서 root계정으로 바로 접속하지 못하게 설정한다.
  • 인증없이 서버에 접속할 수 있도록 하는 설정을 무시하도록 설정한다. 이것은 아주 옛날에 사용되었다.
  • SSH 접속을 허용할 사용자 그룹(Group)를 지정한다.

편집기로 /etc/ssh/sshd_config 를 열어서 다음과 각 항목들을 변경한다.

[root@gserver1 ~]# cat /etc/ssh/sshd_config
... 중략 ...
Port 220
... 중략 ...
IgnoreRhosts yes
... 중략 ...
PermitRootLogin no
... 중략 ...
AllowGroups wheel
... 생략 ...

설정을 변경하였으면 sshd를 재시작하여 시스템에 적용한다.

[root@gserver1 ~]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]

또는

[root@gserver1 ~]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]

위와 같이 설정하면 일반계정으로 접속후 su - 를 하여 root로 권한을 변경해야하는 번거로움이 생기는데, 이에 대한 편의성을 높여주는 sudo를 설정하여 특정 계정 사용자가 root권한을 편하게 사용할 수 있게 한다.

Connecting to 192.168.0.81:220...
Connection established.
Escape character is '^@]'.

Last login: Wed Dec 21 18:01:30 2011 from 192.168.0.102
[jjun@gserver1 ~]$ su -
Password:
[root@gserver1 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@gserver1 ~]# logout
[jjun@gserver1 ~]$ sudo id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

sudo 설정

[root@gserver1 ~]# cat /etc/sudoers

중략...

## Same thing without a password
#%wheel        ALL=(ALL)        NOPASSWD: ALL
중략...

[root@gserver1 ~]# cat /etc/sudoers

중략...
## Same thing without a password
%wheel        ALL=(ALL)        NOPASSWD: ALL
중략...

사용자 추가

[root@gserver1 ~]# useradd -G wheel jjun1
[root@gserver1 ~]# passwd jjun1
Changing password for user jjun1.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

테스트

[root@gserver1 ~]# su - jjun1
[jjun1@gserver1 ~]$ sudo id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[jjun1@gserver1 ~]$ cat /etc/group | grep wheel
wheel:x:10:root,jjun,jjun1

2.7IPv6 중단

어떠한 이유로 IPv6를 중단할려면 아래와 같이 하면된다. 그러나 CentOS 6 FAQ에 의하면 SELinux등과의 호환성 문제로 권장하지 않는다고 한다.

http://wiki.centos.org/FAQ/CentOS6#head-d47139912868bcb9d754441ecb6a8a10d41781df

참고자료 : http://www.proxar.co.uk/technical-support/technical-forum/how-to-disable-ipv6-on-red-hat-6

[root@gserver1 sysconfig]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:AC:C1:09
inet addr:192.168.0.81 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:feac:c109/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11605 errors:0 dropped:0 overruns:0 frame:0
TX packets:1216 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:804736 (785.8 KiB) TX bytes:138162 (134.9 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:16436 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@gserver1 ~]# echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf

[root@gserver1 ~]# reboot
Broadcast message from jjun@gserver1
        (/dev/pts/0) at 14:17 ...

The system is going down for reboot NOW!

[root@gserver1 sysconfig]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:AC:C1:09
inet addr:192.168.0.81 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:759 errors:0 dropped:0 overruns:0 frame:0
TX packets:87 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:52713 (51.4 KiB) TX bytes:10010 (9.7 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 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)

2.8프로그램 설치

CentOS에서 무언가를 하고하 한다면, 다음과 같은 절차를 거치게 된다.

  1. 프로그램 설치
  2. 설정
  3. 서비스 시작
  4. 부팅시 시작되게 설정

그 과정에 대한 복잡한 설명은 이 문서와는 어울리지 않는다. 가볍게 건너뛰고 실제 사용법을 따라가 보자.

프로그램 검색

yum list 프로그램이름

프로그램 설치

yum install 프로그램이름

설정

이 단계를 위해서 간단히 vi나 nano같은 편집기 사용방법을 간단하게 알 필요가 있다.

vi 설정파일
또는
nano 설정파일

서비스 시작

service 서비스이름 start
또는
/etc/init.d/서비스이름 start

부팅시 시작되게 설정

chkconfig 서비스이름 on
확인은
chkconfig --list | grep 서비스이름

반드시 reboot하여 제대로 동작하는지 확인한다.

reboot

패키지 저장소 추가

  • Repoforge

http://repoforge.org/use/ 에서 RPM 파일을 다운로드 받아서 설치한다.

rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

  • EPEL

http://fedoraproject.org/wiki/EPEL 에서 RPM 파일을 다운로드 받아서 설치한다.

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm

  • Remi

http://rpms.famillecollet.com/ 에서 RPM 파일을 다운로드 받아서 설치한다.

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

일단은 disabled되게 설정해 놓자.

그리고

http://wiki.centos.org/PackageManagement/Yum/Priorities 를 설정한다.

이 설정은 여러 Repo에 동일한 패키지를 제공할 경우 우선순위를 설정할 수 있게 한다.

사용방법

yum --enablerepo=저장소이름 옵션

[root@gserver1 ~]# yum check-update
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
* base: centos.mirror.cdnetworks.com
* epel: mirror.bjtu.edu.cn
* extras: centos.mirror.cdnetworks.com
* rpmforge: ftp-stud.fht-esslingen.de
* updates: ftp.daum.net

[root@gserver1 ~]# yum --enablerepo=remi check-update
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
* base: mirror.yongbok.net
* epel: mirror.bjtu.edu.cn
* extras: mirror.yongbok.net
* remi: remi-mirror.dedipower.com
* rpmforge: ftp-stud.fht-esslingen.de
* updates: mirror.yongbok.net

[root@gserver1 ~]# yum --disablerepo=epel,rpmforge,remi check-update
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
* base: mirror.yongbok.net
* extras: mirror.yongbok.net
* updates: mirror.yongbok.net

2.9DenyHosts 설치

참고자료 :

http://www.ravisaive.in/2011/09/how-to-install-denyhosts-to-block-ssh.html

현재 떠 있는 외부 서비스를 확인해보자.

[root@gserver1 ~]# netstat -antlp | grep LISTEN
tcp 0 0 0.0.0.0:220 0.0.0.0:* LISTEN 951/sshd

sshd 가 있을 것이다. 이 순간에 인터넷이 연결되어 있다면, 이 ssh 서비스를 대상으로 무수한 해킹 및 스캔 시도가 있을 것이다. 이것을 감시하고 차단하는 설정을 하도록 한다.

[root@gserver1 ~]# cat /etc/denyhosts.conf | egrep -v "^#|^$"
############ THESE SETTINGS ARE REQUIRED ############
SECURE_LOG = /var/log/secure
HOSTS_DENY = /etc/hosts.deny
PURGE_DENY = 4w
BLOCK_SERVICE = sshd
DENY_THRESHOLD_INVALID = 5
DENY_THRESHOLD_VALID = 10
DENY_THRESHOLD_ROOT = 1
DENY_THRESHOLD_RESTRICTED = 1
WORK_DIR = /var/lib/denyhosts
SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES
HOSTNAME_LOOKUP=YES
LOCK_FILE = /var/lock/subsys/denyhosts
############ THESE SETTINGS ARE OPTIONAL ############
ADMIN_EMAIL = root
SMTP_HOST = localhost
SMTP_PORT = 25
SMTP_FROM = DenyHosts <nobody@localhost>
SMTP_SUBJECT = DenyHosts Report from $[HOSTNAME]
AGE_RESET_VALID=5d
AGE_RESET_ROOT=25d
AGE_RESET_RESTRICTED=25d
AGE_RESET_INVALID=10d
######### THESE SETTINGS ARE SPECIFIC TO DAEMON MODE ##########
DAEMON_LOG = /var/log/denyhosts

DAEMON_SLEEP = 30s
DAEMON_PURGE = 1h
######### THESE SETTINGS ARE SPECIFIC TO ##########
######### DAEMON SYNCHRONIZATION ##########

/etc/hosts.allow

sshd: 192.168.0.33, 192.168.0.44

/etc/hosts.allow 파일이 /etc/hosts.deny 보다 우선한다. 즉, /etc/hosts.deny에 IP가 등록되어 있어도 /etc/hosts.allow에 IP가 있다면, 차단하지 않는다.

[root@gserver1 denyhosts]# ll
total 36
-rw-r--r--. 1 root root 39 Dec 22 17:51 allowed-hosts
-rw-r--r--. 1 root root 27 Dec 22 17:19 allowed-warned-hosts
-rw-r--r--. 1 root root 81 Dec 22 17:56 hosts
-rw-r--r--. 1 root root 81 Dec 22 17:56 hosts-restricted
-rw-r--r--. 1 root root 81 Dec 22 17:56 hosts-root
-rw-r--r--. 1 root root 81 Dec 22 17:56 hosts-valid
-rw-r--r--. 1 root root 80 Dec 22 17:56 offset
-rw-r--r--. 1 root root 0 Dec 22 17:56 suspicious-logins
-rw-r--r--. 1 root root 190 Dec 22 17:56 users-hosts
-rw-r--r--. 1 root root 0 Dec 22 17:56 users-invalid
-rw-r--r--. 1 root root 64 Dec 22 17:56 users-valid
[root@gserver1 denyhosts]# grep 192.168.0.102 *
allowed-warned-hosts:192.168.0.102
hosts:192.168.0.102:0:Thu Dec 22 17:14:45 2011
hosts-restricted:192.168.0.102:0:Thu Dec 22 17:14:45 2011
hosts-root:192.168.0.102:2:Thu Dec 22 17:14:45 2011
hosts-valid:192.168.0.102:1:Thu Dec 22 17:52:00 2011
users-hosts:jjun - 192.168.0.102:1:Thu Dec 22 17:52:00 2011
users-hosts:root - 192.168.0.102:2:Thu Dec 22 17:14:45 2011

[root@gserver1 denyhosts]# tail -f /var/log/secure
Dec 22 17:51:50 gserver1 sshd[1578]: Failed password for jjun from 192.168.0.102 port 49859 ssh2
Dec 22 17:51:52 gserver1 sshd[1578]: Accepted password for jjun from 192.168.0.102 port 49859 ssh2
Dec 22 17:51:52 gserver1 sshd[1578]: pam_unix(sshd:session): session opened for user jjun by (uid=0)
Dec 22 17:51:56 gserver1 sshd[1578]: pam_unix(sshd:session): session closed for user jjun
Dec 22 17:53:22 gserver1 sshd[1612]: Accepted password for jjun from 192.168.0.33 port 1701 ssh2
Dec 22 17:53:22 gserver1 sshd[1612]: pam_unix(sshd:session): session opened for user jjun by (uid=0)
Dec 22 17:54:44 gserver1 sshd[1639]: refused connect from 192.168.0.102 (192.168.0.102)
Dec 22 17:55:33 gserver1 sshd[1645]: Accepted password for jjun from 192.168.0.102 port 49865 ssh2
Dec 22 17:55:33 gserver1 sshd[1645]: pam_unix(sshd:session): session opened for user jjun by (uid=0)
Dec 22 17:55:34 gserver1 sshd[1645]: pam_unix(sshd:session): session closed for user jjun

# jjun이 로그 아웃함
Dec 22 17:58:07 gserver1 sshd[1620]: channel_by_id: 0: bad id: channel free
Dec 22 17:58:07 gserver1 sshd[1620]: Disconnecting: Received ieof for nonexistent channel 0.
Dec 22 17:58:07 gserver1 sshd[1612]: pam_unix(sshd:session): session closed for user jjun

자 이제 LAMP 설치를 위한 기본 OS 준비가 끝났다. 기존의 서적들이 대부분 소스 컴파일 형태로 설명하였으나, 본 책에서는 RPM 설치를 통해 설명한다.

반응형

출처 http://c-faq.com

Q: I'm trying to use pointers to manipulate an array of ints. What's wrong with this code?

        int array[5], i, *ip;
        for(i = 0; i < 5; i++) array[i] = i;
        ip = array;
        printf("%d\n", *(ip + 3 * sizeof(int)));

I expected the last line to print 3, but it printed garbage.

   scaleing을 위해서 뒤에다가 sizeof(int)를 곱해줬는데 이걸로 인해서 존재하지 않는 영역을
건드리게 되면 위와 같이 에러가 난다. 게다가 sizeof(int)는 내가 사용하는 장비에 따라 싸이즈도
다르다. 포인터에서는 자동적으로 스케일되기 때문에 사이즈에 대한 고려는 해주지 않아도
된다는 내용.

A: You're doing a bit more work than you have to, or should. Pointer arithmetic in C is always automatically scaled by the size of the objects pointed to. What you want to say is simply

        printf("%d\n", *(ip + 3));        /* or ip[3] -- see Q 6.3 */

which will print the third element of the array. In code like this, you don't need to worry about scaling by the size of the pointed-to elements--by attempting to do so explicitly, you inadvertently tried to access a nonexistent element past the end of the array (probably array[6] or array[12], depending on sizeof(int) on your machine).

See, however, question 7.19b.

References: K&R1 Sec. 5.3 p. 94

K&R2 Sec. 5.4 p. 103

ISO Sec. 6.3.6

H&S Sec. 7.6.2 p. 204

반응형

'Language > C' 카테고리의 다른 글

nmemb 의미  (8) 2012.07.12
msgsnd/ msgrcv 함수 예제  (12) 2012.07.12
C FAQ (포인터 증가에 대해서)  (6) 2012.07.12
C-FAQ 어찌되었건 pointer 쓰면 정말 좋은가?  (6) 2012.07.12
C FAQ (malloc 오류)  (6) 2012.07.12

출처 http://c-faq.com

Q: Does *p++ increment p, or what it points to?

   

A: The postfix ++ and -- operators essentially have higher precedence than the prefix unary operators. Therefore, *p++ is equivalent to *(p++); it increments p, and returns the value which p pointed to before p was incremented. To increment the value pointed to by p, use (*p)++ (or perhaps ++*p, if the evaluation order of the side effect doesn't matter).

References: K&R1 Sec. 5.1 p. 91

K&R2 Sec. 5.1 p. 95

ISO Sec. 6.3.2, Sec. 6.3.3

H&S Sec. 7.4.4 pp. 192-3, Sec. 7.5 p. 193, Secs. 7.5.7,7.5.8 pp. 199-200

반응형

'Language > C' 카테고리의 다른 글

msgsnd/ msgrcv 함수 예제  (12) 2012.07.12
C FAQ (포인터 증가 2)  (6) 2012.07.12
C-FAQ 어찌되었건 pointer 쓰면 정말 좋은가?  (6) 2012.07.12
C FAQ (malloc 오류)  (6) 2012.07.12
C FAQ (포인터 선언 에러)  (6) 2012.07.12

 출처 http://c-faq.com

Q: What are pointers really good for, anyway?

   

A: They're good for lots of things, such as:

  • dynamically-allocated arrays (see questions 6.14 and 6.16)
  • generic access to several similar variables
  • (simulated) by-reference function parameters (see question 4.8 and 20.1)
  • malloc'ed data structures of all kinds, especially trees and linked lists
  • walking over arrays (for example, while parsing strings)
  • efficient, by-reference ``copies'' of arrays and structures, especially as function parameters

(Note that this is hardly a comprehensive list!)

See also question 6.8.

   

    

반응형

'Language > C' 카테고리의 다른 글

C FAQ (포인터 증가 2)  (6) 2012.07.12
C FAQ (포인터 증가에 대해서)  (6) 2012.07.12
C FAQ (malloc 오류)  (6) 2012.07.12
C FAQ (포인터 선언 에러)  (6) 2012.07.12
mkfifo 함수 예제  (10) 2012.07.06

출처 http://c-faq.com

Q: I'm trying to declare a pointer and allocate some space for it, but it's not working. What's wrong with this code?

char *p;
*p = malloc(10);

 => 언뜻 보기에는 될것 같이 생겼다..

A: The pointer you declared is p, not *p. When you're manipulating the pointer itself (for example when you're setting it to make it point somewhere), you just use the name of the pointer:

        p = malloc(10);

It's when you're manipulating the pointed-to memory that you use * as an indirection operator:

        *p = 'H';

(It's easy to make the mistake shown in the question, though, because if you had used the malloc call as an initializer in the declaration of a local variable, it would have looked like this:

        char *p = malloc(10);

When you break an initialized pointer declaration up into a declaration and a later assignment, you have to remember to remove the *.)

In summary, in an expression, p is the pointer and *p is what it points to (a char, in this example).

See also questions 1.21, 7.1, 7.3c, and 8.3.

References: CT&P Sec. 3.1 p. 28

반응형

'Language > C' 카테고리의 다른 글

C FAQ (포인터 증가에 대해서)  (6) 2012.07.12
C-FAQ 어찌되었건 pointer 쓰면 정말 좋은가?  (6) 2012.07.12
C FAQ (포인터 선언 에러)  (6) 2012.07.12
mkfifo 함수 예제  (10) 2012.07.06
popen 함수 pclose 함수 예제  (6) 2012.07.06

출처 : http://c-faq.com/

Q: What's wrong with this declaration?

char* p1, p2;

I get errors when I try to use p2.

   

A: Nothing is wrong with the declaration--except that it doesn't do what you probably want. The * in a pointer declaration is not part of the base type; it is part of the declarator containing the name being declared (see question 1.21). That is, in C, the syntax and interpretation of a declaration is not really

        type identifier ;

but rather

        base_type thing_that_gives_base_type ;

where ``thing_that_gives_base_type''--the declarator--is either a simple identifier, or a notation like *p or a[10] or f() indicating that the variable being declared is a pointer to, array of, or function returning that base_type. (Of course, more complicated declarators are possible as well.)

In the declaration as written in the question, no matter what the whitespace suggests, the base type is char and the first declarator is ``* p1'', and since the declarator contains a *, it declares p1 as a pointer-to-char. The declarator for p2, however, contains nothing but p2, so p2 is declared as a plain char, probably not what was intended. To declare two pointers within the same declaration, use

        char *p1, *p2;

Since the * is part of the declarator, it's best to use whitespace as shown; writing char* invites mistakes and confusion.

See also question 1.13.

Additional links: Bjarne Stroustrup's opinion

반응형

'Language > C' 카테고리의 다른 글

C-FAQ 어찌되었건 pointer 쓰면 정말 좋은가?  (6) 2012.07.12
C FAQ (malloc 오류)  (6) 2012.07.12
mkfifo 함수 예제  (10) 2012.07.06
popen 함수 pclose 함수 예제  (6) 2012.07.06
pipe 함수 예제  (14) 2012.07.06

원본 출처 : http://bestheroz.blog.me/96293248

   

nmap으로 스캔하는 방법

"nmap -p 1-65535 localhost" 또는 "nmap -p 1-65535 공인IP" 실행하면 현재 자신의 시스템에 어떤 포트가 있는지 모든 포트에 대해 확인 가능하다. 만약 아무런 옵션을 주지 않고 "nmap localhost" 실행하면 사전에 정의된 Well Known 포트에 대해서만 스캔을 한다는 것을 주의하자. 또한 "nmap -p 21,23,53,80 192.168.1.0/24" 같이 스캔할 경우에는 192.168.1.0 대역( 192.168.1.1 부터 192.168.1.255까지 모든 호스트) 대해 21,23,53,80번등의 특정 포트가 열려있는지에 대해서만 스캔을 하게 된다.

   

   

netstat -l 확인해 보는 방법

% netstat -lnp

netstat에서는 많은 옵션을 제공하고 있는데, 현재 시스템 상에서 특정 포트를 점유하여 소켓 데몬 형태로 대기중인 서비스에 대한 사항은 listen 의미인 -l 옵션을 주면된다. 더불어서 -p 옵션을 주면 해당 포트를 사용 중인 program 이름도 확인할 있다.

위의 경우를 보면 좌측에 현재 리슨하고 있는 포트를 있으며 우측에 있는 정보를 보면 해당 포트가 어떤 PID(Process ID)이며 어떤 프로그램인지 확인할 있다. 만약 포트631/tcp 리슨하고 있는 프로세스 정보를 알고자 한다면 pid 2414이고 프로그램 이름이 cupsd 것을 알수 있는데, 상세히 알고자 한다면 앞에서 살펴본 바와 같이 ls -la /proc/<pid> 실행하면 된다.

   

   

tcp 경우 "telnet host_ip 포트번호" 확인하면 된다.

telnet 자체는 tcp 프로토콜이므로 tcp 관련 프로토콜에 대해서만 접속 가능하며 udp 포트에 대한 telnet 접속 시도는 의미가 없다. 따라서 이를테면 snmp 작동하는지 확인하기 위해 161/udp telnet 접속하는 것은 의미가 없다는 뜻이다.

   

   

   

   

   

   

아래의 사이트를 참조하면 특정한 포트 번호가 어떤 역할을 하는지에 대해서 상세한 정보를 얻을 있다.

http://www.grc.com/portdatahelp.htm

http://www.iss.net/security_center/advice/Exploits/Ports/default.htm

http://www.chebucto.ns.ca/~rakerman/port-table.html

http://www.networksorcery.com/enp/nav0204.htm

http://www.practicallynetworked.com/sharing/app_port_list.htm

   

   

   

반응형

+ Recent posts