码迷,mamicode.com
首页 > 其他好文 > 详细

Centos 7 网络配置

时间:2016-03-04 15:58:12      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

Centos 7开始使用ip命令替换了以前的ifconfig

 

ip  [选项]  操作对象{link|addr|route...}

# ip link show                # 显示网络接口信息
# ip link set eth0 upi           # 开启网卡
# ip link set eth0 down          # 关闭网卡
# ip link set eth0 promisc on      # 开启网卡的混合模式
# ip link set eth0 promisc offi     # 关闭网卡的混个模式
# ip link set eth0 txqueuelen 1200   # 设置网卡队列长度
# ip link set eth0 mtu 1400        # 设置网卡最大传输单元
# ip addr show                # 显示网卡IP信息
# ip addr add 192.168.0.1/24 dev eth0 # 设置eth0网卡IP地址192.168.0.1
# ip addr del 192.168.0.1/24 dev eth0 # 删除eth0网卡IP地址

# ip route list                 # 查看路由信息
# ip route add 192.168.4.0/24  via  192.168.0.254 dev eth0 # 设置192.168.4.0网段的网关为192.168.0.254,数据走eth0接口
# ip route add default via  192.168.0.254  dev eth0    # 设置默认网关为192.168.0.254
# ip route del 192.168.4.0/24      # 删除192.168.4.0网段的网关
# ip route del default          # 删除默认路由

 

开启自动获取

首先查看自己的网卡信息

ip addr show

 

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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c9:9b:0b brd ff:ff:ff:ff:ff:ff


可查看到网卡名称为eno16777736

进入network-scripts

[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# ls
ifcfg-eno16777736  ifdown-eth   ifdown-isdn    ifdown-sit       ifup          ifup-ib    ifup-plip   ifup-routes    ifup-tunnel        network-functions-ipv6
ifcfg-lo           ifdown-ib    ifdown-post    ifdown-Team      ifup-aliases  ifup-ippp  ifup-plusb  ifup-sit       ifup-wireless
ifdown             ifdown-ippp  ifdown-ppp     ifdown-TeamPort  ifup-bnep     ifup-ipv6  ifup-post   ifup-Team      init.ipv6-global
ifdown-bnep        ifdown-ipv6  ifdown-routes  ifdown-tunnel    ifup-eth      ifup-isdn  ifup-ppp    ifup-TeamPort  network-functions
[root@localhost network-scripts]#

可以查看到我们相应网卡的配置文件为ifcfg-eno16777736

使用vi ifcfg-eno16777736

进入编辑

TYPE=Ethernet
BOOTPROTO=dhcp
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=eno16777736
UUID=5b96b479-11f3-4aec-b984-129de5721e7b
DEVICE=eno16777736
ONBOOT=no

将ONBOOT=no修改为ONBOOT=yes并保存退出重启

重启后再次使用ip addr show可查看到

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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c9:9b:0b brd ff:ff:ff:ff:ff:ff
    inet 192.168.133.133/24 brd 192.168.133.255 scope global dynamic eno16777736
       valid_lft 1252sec preferred_lft 1252sec
    inet6 fe80::20c:29ff:fec9:9b0b/64 scope link
       valid_lft forever preferred_lft forever

我们网卡已经自动获取到ip了

手工设置IP地址:

 

TYPE=Ethernet
#BOOTPROTO=dhcp
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=eno16777736
UUID=5b96b479-11f3-4aec-b984-129de5721e7b
DEVICE=eno16777736
ONBOOT=yes
IPADDR0=192.168.133.130
PREFIX0=24
GETWAY0=192.168.133.2
DNS1=192.68.133.2
DNS2=218.85.152.99

通过上面配置。我们为系统指定ip 子网掩码 网关以及DNS地址。

[root@localhost ~]# ip addr show
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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c9:9b:0b brd ff:ff:ff:ff:ff:ff
    inet 192.168.133.130/24 brd 192.168.133.255 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fec9:9b0b/64 scope link
       valid_lft forever preferred_lft forever

习惯使用ifconfig的可以实现联网后通过yum install net-tools安装net-tools组件使用ifconfig。

 

Centos 7 网络配置

标签:

原文地址:http://www.cnblogs.com/my-jin/p/5242217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!