네트워크 아이피 수동설정
I’ve installed Red Hat enterprise Linux 6 (minimal install) and I added Nic card (NIC). How do I configure the network card from the command line?
There are 3 steps involved
- Configure the network card to recieve Static or DHCP IP
- Configure your hostname and gateway
- Configure your DNS
Configure the network card
Edit configuration files stored in /etc/sysconfig/network-scripts/
You can configure network card by editing text files stored in /etc/sysconfig/network-scripts/directory. First change directory to /etc/sysconfig/network-scripts/:
# cd /etc/sysconfig/network-scripts/
You need to edit / create files as follows:
- /etc/sysconfig/network-scripts/ifcfg-eth0: First Ethernet card configuration file
- /etc/sysconfig/network-scripts/ifcfg-eth1: Second Ethernet card configuration file
To edit/create first NIC file, type command:
# vi ifcfg-eth0
Append/modify as follows:
# Intel Corporation 82573E Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=10.10.10.15
NETMASK=255.255.255.192
ONBOOT=yes
Save and close the file. Define default gateway (router IP) and hostname in /etc/sysconfig//network file:
# vi /etc/sysconfig/network
Append/modify configuration as follows:
NETWORKING=yes
HOSTNAME=myserver.example.com
GATEWAY=10.10.10.1
Restart networking:
# /etc/init.d/network restart
Setup DNS server defined in /etc/resolv.conf file:
# vi /etc/resolv.conf
Setup DNS Server as follows:
nameserver 8.8.8.8
nameserver 8.8.4.4
Save and close the file. Now you can ping the gateway/other hosts:
$ ping google.com
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
추가설명
- /etc/hosts
-
The main purpose of this file is to resolve hostnames that cannot be resolved any other way. It can also be used to resolve hostnames on small networks with no DNS server. Regardless of the type of network the computer is on, this file should contain a line specifying the IP address of the loopback device (127.0.0.1) as localhost.localdomain. For more information, refer to the hosts man page.
- /etc/resolv.conf
-
This file specifies the IP addresses of DNS servers and the search domain. Unless configured to do otherwise, the network initialization scripts populate this file. For more information about this file, refer to the resolv.conf man page.
- /etc/sysconfig/network
-
This file specifies routing and host information for all network interfaces. For more information about this file and the directives it accepts, refer to Section 27.1.22, “/etc/sysconfig/network”.
- /etc/sysconfig/network-scripts/ifcfg-<interface-name>
-
For each network interface, there is a corresponding interface configuration script. Each of these files provide information specific to a particular network interface. Refer to Section 13.2, “Interface Configuration Files” for more information on this type of file and the directives it accepts.
CentOS를 Desktop 이나 devel 로 설치하면 불필요하게 설치되는 패키지가 많아서 minimal 로 설치하고 login 해 보니 네트웍 설정이 되어 있지 않았고 system-config-network-tui 같은 설정 utility 도 설치가 되어 있지 않았다.
네트웍이 안 되므로 yum 으로 설치할 수도 없고 해서 수동으로 Network 설정하는 방법을 정리해 본다.
- vi /etc/sysconfig/network-scripts/ifcfg-eth0
-
다음 내용을 추가한다.
※ IP 는 192.168.254.231, GW=192.168.254.2, DNS=192.168.254.2, MAC=00:21:5e:30:10:9e 로 가정한다.DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:21:5e:30:10:9e
NM_CONTROLLED=no
NETMASK=255.255.254.0
GATEWAY=192.168.254.2
DNS1=192.168.254.2
IPADDR=192.168.254.231
TYPE=Ethernet
IPV6INIT=no
USERCTL=no
- service network restart
- yum search bind-utils 등 network을 사용하는 명령어를 사용하여 정상 동작 여부를 확인한다.
minimal 로 설치후 yum 으로 설치할 패키지
기본 유틸리티
# nslookup
yum -y install bind-utils
# vim
yum -y install vim
# ntsysv - 콘솔에서 service runlevel 편집, chkconfig 를 써도 되지만 익숙해서 설치
yum -y install ntsysv
# firewall console 설정 도구
yum -y install system-config-firewall-tui
gcc 관련 패키지
- yum install gcc gcc-c++ make subversion
X-Windows & Gnome Desktop
- yum groupinstall "X Window System" "GNOME Desktop Environment" " libX11-devel "