centerOS设置静态IP

centerOS设置静态IP,使用的是NAT模式

1.通过命令查看当前Ip地址: $ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:51:00:18  
          inet addr:192.168.43.10  Bcast:192.168.43.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe51:18/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:1790 (1.7 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:18 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1448 (1.4 KiB)  TX bytes:1448 (1.4 KiB)

2.登录超级管理帐号:$su

输入密码:

3.进入/etc/sysconfig/network-scripts/目录

#cd /etc/sysconfig/network-scripts/

4.查看当前目录下的文件

# ls

[root@localhost network-scripts]# ls
ifcfg-eth0   ifdown-isdn    ifup-aliases  ifup-plusb     init.ipv6-global
ifcfg-lo     ifdown-post    ifup-bnep     ifup-post      net.hotplug
ifdown       ifdown-ppp     ifup-eth      ifup-ppp       network-functions
ifdown-bnep  ifdown-routes  ifup-ippp     ifup-routes    network-functions-ipv6
ifdown-eth   ifdown-sit     ifup-ipv6     ifup-sit
ifdown-ippp  ifdown-tunnel  ifup-isdn     ifup-tunnel
ifdown-ipv6  ifup           ifup-plip     ifup-wireless


5.修改ifcfg-eth0文件(需要超级管理员权限才能保存wen'jian)

#vim ifcfg-eth0 

进入文件后按 i编辑文件

IPADDR=192.168.2.10
NETMASK=255.255.255.0
GATEWAY=192.168.2.2
DNS1=192.168.2.2

编辑完成后按esc  :wq保存文件,通过cat ifcfg-eth0查看文件

6.使配置文件生效

#service network restart

[root@localhost network-scripts]# service network restart
Shutting down interface eth0:  Device state: 3 (disconnected)
                                                           [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/2
state: activated
Connection activated
                                                           [  OK  ]

7.检查是否可以访问外网

#curl www.baidu.com

返回baidu的网页信息,说明配置成功。








阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页