centos6.4配置ip dns

来源:互联网 发布:ios软件安装目录 编辑:程序博客网 时间:2024/05/16 04:39

CentOS 6.4下载地址:http://mirrors.163.com/  网易开源镜像

我选择的是迷你版300M大小

完成CentOS 6.4的安装,下面开始设置:


一、设置IP地址

1、把虚拟机的网卡设成“桥接”


2、修改对应网卡的IP地址的配置文件

vi /etc/sysconfig/network-scripts/ifcfg-eth0 

修改以下内容 

DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0 

BOOTPROTO=static #设置网卡获得ip地址的方式,可能的选项为static,dhcp或bootp,分别对应静态指定的 ip地址,通过dhcp协议获得的ip地址,通过bootp协议获得的ip地址 

BROADCAST=192.168.1.255 #对应的子网广播地址 

HWADDR=00:07:E9:05:E8:B4 #对应的网卡物理地址 

IPADDR=192.168.1.2 #如果设置网卡获得 ip地址的方式为静态指定,此字段就指定了网卡对应的ip地址 

IPV6INIT=no

IPV6_AUTOCONF=no 

NETMASK=255.255.255.0 #网卡对应的网络掩码 

NETWORK=192.168.1.0 #网卡对应的网络地址 

ONBOOT=yes #系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备


3、修改网关

修改对应网卡的网关的配置文件

vi /etc/sysconfig/network

修改以下内容

NETWORKING=yes(表示系统是否使用网络,一般设置为yes。如果设为no,则不能使用网络,而且很多系统服务程序将无法启动)

HOSTNAME=centos(设置本机的主机名,这里设置的主机名要和/etc/hosts中设置的主机名对应)

GATEWAY=192.168.1.1(设置本机连接的网关的IP地址。例如,网关为10.0.0.2)


4、修改DNS

修改对应网卡的DNS的配置文件

vi /etc/resolv.conf

修改以下内容

nameserver 8.8.8.8 #google域名服务器

nameserver 8.8.4.4 #google域名服务器


5、重新启动网络配置

service network restart  或  /etc/init.d/network restart


6、其他技巧

修改 IP 地址

即时生效:

# ifconfig eth0 192.168.1.2 netmask255.255.255.0

启动生效:

修改/etc/sysconfig/network-scripts/ifcfg-eth0


修改网关

即时生效:

# route add default gw 192.168.1.1 dev eth0

启动生效:

修改 /etc/sysconfig/network


修改 DNS

修改/etc/resolv.conf

修改后可即时生效,启动同样有效


修改 hostname

即时生效:

# hostname centos1

启动生效:

修改/etc/sysconfig/network



二、配置防火墙

1、防火墙的设置

关闭防火墙:/etc/init.d/iptables stop

打开防火墙:/etc/init.d/iptables start

重启防火墙:/etc/init.d/iptables restart

查看防火墙:/etc/init.d/iptables status

永久关闭防火墙:chkconfig iptables off

打开指定端口:/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT #80为指定端口

将更改进行保存:/etc/rc.d/init.d/iptables save


或直接在/etc/sysconfig/iptables中增加一行:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT


2、查看端口

看ipp协议默认使用的端口可以通过这个命令:

   cat /etc/service|grep ipp

查看所有被打开的端口一个是netstat,一个是ss

   netstat -tanp

t代表TCP协议,还有u(UDP)、w(RAW)、x(UNIX)

a代表全部(all)

n:直接显示端口号,而不是根据“/etc/server”显示端口对应的服务名称

p:显示占用该端口号的进程。

l:显示正在被监听的端口。



三、安装WEB服务器

1、安装nginx

rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

yum info nginx  #查看yum的nginx信息

yum install nginx  #安装nginx

service nginx start  #启动nginx



四、安装其他程序

yum check-update

yum -y install mysql-server  php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator


添加nginx 默认主页index.php

vim /etc/nginx/conf.d/default.conf


location / {

        root   /usr/share/nginx/html;

        index  index.html index.htm index.php;

    }


配置nginx支持php

vim /etc/nginx/conf.d/default.conf


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    location ~ .php$ {

        root           html;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;

        include        fastcgi_params;

    }


配置php-fpm

vim /etc/php-fpm.d/www.conf


; Unix user/group of processes

; Note: The user is mandatory. If the group is not set, the default user's group

;       will be used.

; RPM: apache Choosed to be able to access some dir as httpd

user = nginx

; RPM: Keep a group allowed to write in log dir.

group = nginx


service nginx start   #启动nginx

/etc/rc.d/init.d/php-fpm start   #启动php-fpm

原创粉丝点击