Original link: http://blog.csdn.net/johnnycode/article/details/40624403
This study is mainly for Centos 7.0.1406 version to learn to organize!
If you use VirtualBox to configure CentOS then please refer to my article CentOS 7 learning static IP settings (cont.)
1, edit the Ifcfg-eth0 file, vim minimized installation is not installed, need to install the self-description.
[Plain]View PlainCopy
- # Vim/etc/sysconfig/network-scripts/ifcfg-eth0
2, modify the following content
[Plain]View PlainCopy
- bootproto= "Static" #dhcp改为static
- onboot= "Yes" #开机启用本配置
- ipaddr=192.168.7.106 #静态IP
- gateway=192.168.7.1 #默认网关
- netmask=255.255.255.0 #子网掩码
- dns1=192.168.7.1 #DNS Configuration
3. Effect after modification
[Plain]View PlainCopy
- #]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0
- Hwaddr= "00:15:5d:07:f1:02"
- Type= "Ethernet"
- bootproto= "Static" #dhcp改为static
- Defroute= "Yes"
- Peerdns= "Yes"
- Peerroutes= "Yes"
- Ipv4_failure_fatal= "No"
- ipv6init= "Yes"
- ipv6_autoconf= "Yes"
- Ipv6_defroute= "Yes"
- Ipv6_peerdns= "Yes"
- Ipv6_peerroutes= "Yes"
- Ipv6_failure_fatal= "No"
- Name= "Eth0"
- Uuid= "Bb3a302d-dc46-461a-881e-d46cafd0eb71"
- onboot= "Yes" #开机启用本配置
- ipaddr=192.168.7.106 #静态IP
- gateway=192.168.7.1 #默认网关
- netmask=255.255.255.0 #子网掩码
- dns1=192.168.7.1 #DNS Configuration
4. Restart the Network Service
[Plain]View PlainCopy
- # Service Network Restart
5, see the effect after the change, Centois 7 no longer use ifconfig instead of using the IP command to view network information.
[Plain]View PlainCopy
- # IP Addr
- 1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN
- Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
- inet 127.0.0.1/8 Scope host Lo
- Valid_lft Forever Preferred_lft Forever
- INET6:: 1/128 Scope Host
- Valid_lft Forever Preferred_lft Forever
- 2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU qdisc pfifo_fast State UNKNOWN Qlen 1000
- Link/ether 00:15:5d:07:f1:02 BRD FF:FF:FF:FF:FF:FF
- inet 192.168.7.106/24 BRD 192.168.7.255 Scope Global eth0
- Valid_lft Forever Preferred_lft Forever
- Inet6 FE80::215:5DFF:FE07:F102/64 Scope link
- Valid_lft Forever Preferred_lft Forever
Static IP is set at installation but only 127.0.0.1 IP address when using the Ifconfig command
At this time see if there is a Ifcfg-eth0 file under the/etc/sysconfig/network-scripts directory if there is no file to see if there is a ifcfg-beginning
My system exists ifcfg-eno16777736 such a file
More ifcfg-eno16777736
[Email protected] network-scripts]$ more ifcfg-eno16777736
Type=ethernet
Bootproto=none
Defroute=yes
Ipv4_failure_fatal=no
Ipv6init=yes
Ipv6_autoconf=yes
Ipv6_defroute=yes
Ipv6_failure_fatal=no
name=eno16777736
Uuid=7170eda3-8183-41fc-b0b8-ee924d05ddc2
Onboot=no
ipaddr0=192.168.0.88
Prefix0=24
hwaddr=00:0c:29:61:34:7d
Ipv6_peerdns=yes
Ipv6_peerroutes=yes
Just for the IP information I added when I installed the system
At this point, use the command CP ifcfg-eno16777736 Ifcfg-eth0 to create the Ifcfg-eth0 file and change the Onboot=no in the content to Onboot=yes
Execute Command Service network restart
Execute ifconfig The correct network information appears
Eno16777736:flags=4163<up,broadcast,running,multicast> MTU 1500
inet 192.168.0.88 netmask 255.255.255.0 broadcast 192.168.0.255
Inet6 fe80::20c:29ff:fe61:347d Prefixlen ScopeID 0x20<link>
Ether 00:0c:29:61:34:7d Txqueuelen (Ethernet)
RX Packets 102 Bytes 10385 (10.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX Packets Bytes 13681 (13.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Lo:flags=73<up,loopback,running> MTU 65536
inet 127.0.0.1 netmask 255.0.0.0
Inet6:: 1 prefixlen ScopeID 0x10Loop Txqueuelen 0 (Local Loopback)
RX Packets 818 Bytes 71132 (69.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX Packets 818 Bytes 71132 (69.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
If the installation environment is host-only for VM VMS, you want to surf the Internet in the virtual machine
Find the network card in the win environment Vmnet1 to see his IP address through the property TCP/IP protocol
Assuming this is 192.168.0.12 and the IP set in the virtual machine is ipaddr0=192.168.0.88 need to add the gateway to the IP address of the current win Vmnet1 in Ifcfg-eth0
That is, add geteway=192.168.0.12
On win must have a network card such as My notebook for the wireless card right-click Properties Advanced Allow other networks to connect through this computer's internet to hook up and down the box to select the Vmnet network card
Ok if pop-up confirm select No
To view the wireless network card DNS server through the Ipconfig-all command such as my
Ethernet Adapter Wireless network connection:
connection-specific DNS Suffix .:
&NBSP ; Description ........... : Broadcom 802.11n Network
physical Address ...: 08-3e-8e-4a-38-ab
&NBSP ; DHCP Enabled ..... : Yes
autoconfiguration Enabled ...: Yes
IP address. ....: 192.168.1.100
Subnet Mask ...........:255.255.255.0
&N Bsp Default Gateway ..... . : 192.168.1.1
DHCP Server ...: 192.168.1.1
&NBSP ; DNS Servers ........... : 211.162.66.66
&NBSP ; 211.162.77.77
Add a DNS server to Ifcfg-eth0 I've got two here.
Add two lines
dns1=211.162.66.66
dns2=211.162.77.77
At this point, the Linux Restart Service network restart on the virtual machine
Ping www.baidu.com Success
-
http://blog.csdn.net/johnnycode/article/details/40624403
Centos 7 Learning static IP settings