CentOS下设置IP、网关、DNS

设置系统的主机名:hostname linux.test(直接使用hostname可以显示当时系统的主机名)

          启用eth0: ifconfig eth0 up(down)或ifup eht0

     查看网络配置: ifconfig -a

        设置IP地址: ifconfig eth0 192.168.1.45 netmask 255.255.255.0 up(up是表示立即激活)

     重启网络设置: service network restart

查看当前路由信息: route

           删除路由: route del -net 169.254.0.0 netmask 255.255.0.0

           添加路由: route add -net 169.254.0.0 netmask 255.255.0.0 dev eth0

     设置默认网关: route add default gw 192.168.1.1

          设置DNS: echo "nameserver 211.98.1.28">> /etc/resolv.conf

 

以下是网摘:

在Linux中不管你是做服务器还是只是平常使用,上网肯定都是最重要和不可缺少的一个因素之一,所以就涉及到它的ip gateway dns等network配置和使用。

但是设置linux网络的方法有两种:
第一种:使用命令修改(直接即时生效,重启失效) #ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up

说明: eth0是第一个网卡,其他依次为eth1,eth* 192.168.0.1是给网卡配置的第一个网卡配置的ip地址 netmask 255.255.255.0 配置的是子网掩码 up是表示立即激活
gateway # route add default gw 192.168.30.1 eth0
dns: # vi etc/resolv.conf nameserver 202.131.80.1 nameserver 202.131.80.5
如果要重起生效,就把这些写到起动脚本 rc.local中
第二种:修改配置文档(需要重启网络配置,永远生效)
一、修改IP地址 vi /etc/sysconfig/network-scripts/ifcfg-eth0

[aeolus@db1 network-scripts]$ vi ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=static

IPADDR=192.168.30.197

NETMASK=255.255.255.0

GATEWAY=192.168.30.1
二、修改网关 vi /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=Aaron

GATEWAY=192.168.30.1
三、修改DNS

[aeolus@db1 etc]$ vi resolv.conf nameserver 202.131.80.1 nameserver 202.131.80.0

(一般现在这样设置以后都要重启network,所以还涉及到网络重启配置)
四、重新启动网络配

root账户下

1: # service network restart

2:# /etc/init.d/network restart

3:# ifdown eth0        # ifup eth0

4:# ifconfig eth0 down      # ifconfig eth0 up
五、启动和关闭防火墙

      即时生效: 1:#service iptables start #service iptables stop
重启系统生效: 2:#service iptables on #service iptables off      当然ip gateway dns都是随你的网络改变而改变的

posted @ 2015-09-23 13:33  李有定  阅读(536)  评论(0编辑  收藏  举报