linux学习——网络配置

本地资源:系统:rhel7.0 ( Linux localhost.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux)

               (还没有组建局域网)
下面是步骤及成果展示:

查看本机的局域网ip>

[root@localhost test]# ifconfig |less


br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.199  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::221:ccff:fe64:ac5c  prefixlen 64  scopeid 0x20<link>
        ether 00:21:cc:64:ac:5c  txqueuelen 0  (Ethernet)
        RX packets 13  bytes 2152 (2.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19  bytes 2291 (2.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s25: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:21:cc:64:ac:5c  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf2500000-f2520000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 43942  bytes 10667962 (10.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0

设置本机的ip

第一种方式:手动设置

[root@localhost test]# vim /etc/sysconfig/network-scripts/ifcfg-enp0s25
DEVICE="enp0s25"
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.3.110
GATEWAY=192.168.3.252
NETMASK=255.255.255.0
DNS1=192.168.3.252
BRIDGE=br0

第二种方式:自动获取

DEVICE="enp0s25"
ONBOOT=yes
NETBOOT=yes
BOOTPROTO=dhcp

TYPE=Ethernet

NAME="enp0s25"

如果还想和虚拟机通过桥接建立联系,请参考以下设置

                                                                             >网桥搭建<

第一步:创建br0网桥配置:让虚拟机接入主机的网段

[root@localhost test]# vim /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE="br0"
ONBOOT=yes
NETBOOT=yes
BOOTPROTO=none
IPADDR=192.168.3.199
GATEWAY=192.168.3.252
NETMASK=255.255.255.0
DNS1=192.168.3.252
TYPE=Bridge

第二步:因为前面已经设置成桥接了
BRIDGE=br0,这里不再赘述

第三步:重启网络systemctl restart network

******************************************ok,下面是问题,希望有大神帮忙看一下*******************************************

   这里有个问题,我的主机重启网络,第一次重启失败,我再试一次就成功了。具体如下:

 [root@localhost test]# systemctl restart network
Job for network.service failed. See 'systemctl status network.service' and 'journalctl -xn' for details.
[root@localhost test]# systemctl restart network

我试了网上说的方法,并没有见效,我参考的是这个方法:

[root@localhost test]# systemctl status network
network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network)
   Active: failed (Result: exit-code) since Sat 2016-02-06 16:30:08 CST; 8s ago
  Process: 21899 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
  Process: 22190 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)

Feb 06 16:29:57 localhost.localdomain network[22190]: Bringing up interface A...
Feb 06 16:29:57 localhost.localdomain network[22190]: Bringing up interface e...
Feb 06 16:29:57 localhost.localdomain network[22190]: [  OK  ]
Feb 06 16:29:57 localhost.localdomain network[22190]: Bringing up interface v...
Feb 06 16:29:57 localhost.localdomain network[22190]: Bringing up interface b...
Feb 06 16:30:08 localhost.localdomain network[22190]: Bringing up interface v...
Feb 06 16:30:08 localhost.localdomain network[22190]: [FAILED]
Feb 06 16:30:08 localhost.localdomain systemd[1]: network.service: control pr...
Feb 06 16:30:08 localhost.localdomain systemd[1]: Failed to start LSB: Bring ...
Feb 06 16:30:08 localhost.localdomain systemd[1]: Unit network.service entere...
Hint: Some lines were ellipsized, use -l to show in full.

然后我套用了各种做法,网上大多设定开机启动一个名为NetworkManager-wait-online服务,命令为:
systemctl enable NetworkManager-wait-online.service




你可能感兴趣的:(linux,网络,RHEL,X86)