ceph存储 Linux 网卡配置-centos&ubuntu
2015-04-09 14:24
543 查看
Linux中不同distribution中配置网络的方法大同小异。以下介绍RHEL6系列,SUSE11, Ubuntu12.04的配置
CentOS,RHEL
/etc/sysconfig/network
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
NETWORKING=yes # 系统启动时是否启动网络
HOSTNAME=zhubinqiangPC # 定义主机名
/etc/udev/rules.d/70-persistent-net.rules 得到网卡的MAC地址
[html]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:58:5f:4b", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
DEVICE=eth0 # 网卡代号,必须与ifcfg-eth0相对于
HWADDR=00:0c:29:58:5f:4b # MAC 地址, 如果只有一个网卡,可以省略
TYPE=Ethernet # 网络接口格式 这里是以太网格式
UUID=371ea884-5bb7-4e03-9913-127fd7e787ae # nmcli con 可得到 未知什么意思
ONBOOT=yes # 开机启动
NM_CONTROLLED=yes # controlled by NetworkManager
BOOTPROTO=static # static 和 none 功能相同,表示手动配置, dhcp表示动态获取IP
IPADDR=192.168.1.211 # IP 地址
NETMASK=255.255.255.0 # 子网掩码
GATEWAY=192.168.1.1 # 默认网关,如果有多个网卡配置文件 只须配置一个即可
USERCTL=no # 是否允许非root用户控制该设备
PEERDNS=yes # yes表示由DHCP来获取DNS, no表示 /etc/resolv.conf 来控制
IPV6INIT=no # 是否允许IPV6
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
/etc/init.d/network restart
[plain]
view plaincopyprint?
ifconfig -a
此配置在重启网络后会失效,恢复为ifcfg-eth0为主的配置
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
ifconfig eth0 192.168.0.211 netmask 255.255.255.0
ifconfig eth0 192.168.0.211/24
修改网卡MAC地址
[plain]
view plaincopyprint?
ifconfig eth0 hw ether 00:0C:29:58:5F:4C
开启和禁用网卡
[plain]
view plaincopyprint?
ifconfig eth0 up
ifconfig eth0 down
注意 一旦用ifconfig 来激活 就不能用ifdown来关闭。 一定要ifconfig才行。因为ifdown会比较当前网络与ifcfg-eth0是否相同,如果不同放弃ifdown的操作
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
ifup eth0 #激活
ifdown eth0 #关闭
ifconfig eth0 up #激活
ifconfig eth0 down #关闭
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
# Generated by NetworkManager
domain localdomain
search localdomain # 查找计算机名是 默认属于该域
nameserver 192.168.157.2 # DNS 服务器地址, 可以配置多个
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
dhclient eth0
/etc/hosts 配置
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
修改hostname
1.修改/etc/sysconfig/network
2.修改/etc/hosts
通过lshw 得到MAC地址
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
lshw -c network
description: Ethernet interface
product: 79c970 [PCnet32 LANCE]
vendor: Hynix Semiconductor (Hyundai Electronics)
physical id: 1
bus info: pci@0000:02:01.0
logical name: eth0
version: 10
serial: 00:0c:29:77:82:a2
width: 32 bits
clock: 33MHz
capabilities: bus_master rom ethernet physical logical
configuration: broadcast=yes driver=pcnet32 driverversion=1.35 ip=192.168.157.183 latency=64 link=yes maxlatency=255 mingnt=6 multicast=yes
resources: irq:19 ioport:2000(size=128) memory:d8400000-d840ffff
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static # 如果是dhcp 则把static改为dhcp
hwaddress ether 00:13:20:f9:f4:d3 #MAC
address 192.168.1.10 # IP 地址
netmask 255.255.255.0 # 子网掩码
gateway 192.168.1.1 # 网关
重启网络 生效配置
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
/etc/init.d/networking restart
/etc/hosts 配置
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
127.0.0.1 localhost
127.0.1.1 zbq-pc
192.168.157.136 zbq-pc
192.168.157.151 itms-server
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
cat /etc/udev/rules.d/70-persistent-net.rules 查看MAC
修改 /etc/sysconfig/network/ifcfg-eth0
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
BOOTPROTO='dhcp'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR=''
MTU=''
NAME='82545EM Gigabit Ethernet Controller (Copper)'
NETMASK=''
NETWORK=''
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
/etc/init.d/network restart
CentOS,RHEL
/etc/sysconfig/network
[plain]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
NETWORKING=yes # 系统启动时是否启动网络
HOSTNAME=zhubinqiangPC # 定义主机名
<span style="font-size:12px;">NETWORKING=yes # 系统启动时是否启动网络 HOSTNAME=zhubinqiangPC # 定义主机名</span>
/etc/udev/rules.d/70-persistent-net.rules 得到网卡的MAC地址
[html]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:58:5f:4b", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
<span style="font-size:12px;">SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:58:5f:4b", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"</span>
/etc/sysconfig/network-scripts/ifcfg-eth0 配置网卡
配置项有很多个,以下只列出部分重要的。具体可以参考 /usr/share/doc/initscripts-*/sysconfig.txt[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
DEVICE=eth0 # 网卡代号,必须与ifcfg-eth0相对于
HWADDR=00:0c:29:58:5f:4b # MAC 地址, 如果只有一个网卡,可以省略
TYPE=Ethernet # 网络接口格式 这里是以太网格式
UUID=371ea884-5bb7-4e03-9913-127fd7e787ae # nmcli con 可得到 未知什么意思
ONBOOT=yes # 开机启动
NM_CONTROLLED=yes # controlled by NetworkManager
BOOTPROTO=static # static 和 none 功能相同,表示手动配置, dhcp表示动态获取IP
IPADDR=192.168.1.211 # IP 地址
NETMASK=255.255.255.0 # 子网掩码
GATEWAY=192.168.1.1 # 默认网关,如果有多个网卡配置文件 只须配置一个即可
USERCTL=no # 是否允许非root用户控制该设备
PEERDNS=yes # yes表示由DHCP来获取DNS, no表示 /etc/resolv.conf 来控制
IPV6INIT=no # 是否允许IPV6
<span style="font-size:12px;">DEVICE=eth0 # 网卡代号,必须与ifcfg-eth0相对于 HWADDR=00:0c:29:58:5f:4b # MAC 地址, 如果只有一个网卡,可以省略 TYPE=Ethernet # 网络接口格式 这里是以太网格式 UUID=371ea884-5bb7-4e03-9913-127fd7e787ae # nmcli con 可得到 未知什么意思 ONBOOT=yes # 开机启动 NM_CONTROLLED=yes # controlled by NetworkManager BOOTPROTO=static # static 和 none 功能相同,表示手动配置, dhcp表示动态获取IP IPADDR=192.168.1.211 # IP 地址 NETMASK=255.255.255.0 # 子网掩码 GATEWAY=192.168.1.1 # 默认网关,如果有多个网卡配置文件 只须配置一个即可 USERCTL=no # 是否允许非root用户控制该设备 PEERDNS=yes # yes表示由DHCP来获取DNS, no表示 /etc/resolv.conf 来控制 IPV6INIT=no # 是否允许IPV6</span>
修改完配置文件要重启网络
[plain]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
/etc/init.d/network restart
<span style="font-size:12px;">/etc/init.d/network restart</span>
通过ifconfig来配置网络
查看所有网卡[plain]
view plaincopyprint?
ifconfig -a
<span style="font-size:12px;">ifconfig -a</span>
此配置在重启网络后会失效,恢复为ifcfg-eth0为主的配置
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
ifconfig eth0 192.168.0.211 netmask 255.255.255.0
ifconfig eth0 192.168.0.211/24
<span style="font-size:12px;">ifconfig eth0 192.168.0.211 netmask 255.255.255.0 ifconfig eth0 192.168.0.211/24 </span>
修改网卡MAC地址
[plain]
view plaincopyprint?
ifconfig eth0 hw ether 00:0C:29:58:5F:4C
<span style="font-size:12px;">ifconfig eth0 hw ether 00:0C:29:58:5F:4C</span>
开启和禁用网卡
[plain]
view plaincopyprint?
ifconfig eth0 up
ifconfig eth0 down
<span style="font-size:12px;">ifconfig eth0 up ifconfig eth0 down</span>
ifup和ifdown来激活与关闭网卡
用ifup来激活 ifcfg-eth0文件要配置正确, 实际是通过/sbin/ifup 来调用相关脚本。注意 一旦用ifconfig 来激活 就不能用ifdown来关闭。 一定要ifconfig才行。因为ifdown会比较当前网络与ifcfg-eth0是否相同,如果不同放弃ifdown的操作
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
ifup eth0 #激活
ifdown eth0 #关闭
ifconfig eth0 up #激活
ifconfig eth0 down #关闭
<span style="font-size:12px;">ifup eth0 #激活 ifdown eth0 #关闭 ifconfig eth0 up #激活 ifconfig eth0 down #关闭</span>
/etc/resolv.conf 定义DNS服务器
[plain]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
# Generated by NetworkManager
domain localdomain
search localdomain # 查找计算机名是 默认属于该域
nameserver 192.168.157.2 # DNS 服务器地址, 可以配置多个
<span style="font-size:12px;"># Generated by NetworkManager domain localdomain search localdomain # 查找计算机名是 默认属于该域 nameserver 192.168.157.2 # DNS 服务器地址, 可以配置多个</span>
通过DHCP获取IP
通过修改ifcfg-ethX的BOOTPROTO=dhcp并重启网络 或者以下方法[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
dhclient eth0
<span style="font-size:12px;">dhclient eth0</span>
/etc/hosts 配置
[plain]
view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
<span style="font-size:12px;">127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 </span>
修改hostname
1.修改/etc/sysconfig/network2.修改/etc/hosts
Ubuntu12.04
参考官方文档 https://help.ubuntu.com/12.04/serverguide/network-configuration.html通过lshw 得到MAC地址
[plain]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
lshw -c network
<span style="font-size:12px;">lshw -c network </span>*-network
description: Ethernet interface
product: 79c970 [PCnet32 LANCE]
vendor: Hynix Semiconductor (Hyundai Electronics)
physical id: 1
bus info: pci@0000:02:01.0
logical name: eth0
version: 10
serial: 00:0c:29:77:82:a2
width: 32 bits
clock: 33MHz
capabilities: bus_master rom ethernet physical logical
configuration: broadcast=yes driver=pcnet32 driverversion=1.35 ip=192.168.157.183 latency=64 link=yes maxlatency=255 mingnt=6 multicast=yes
resources: irq:19 ioport:2000(size=128) memory:d8400000-d840ffff
/etc/network/interfaces 配置网卡
[plain]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static # 如果是dhcp 则把static改为dhcp
hwaddress ether 00:13:20:f9:f4:d3 #MAC
address 192.168.1.10 # IP 地址
netmask 255.255.255.0 # 子网掩码
gateway 192.168.1.1 # 网关
<span style="font-size:12px;">auto lo iface lo inet loopback auto eth0 iface eth0 inet static # 如果是dhcp 则把static改为dhcp hwaddress ether 00:13:20:f9:f4:d3 #MAC address 192.168.1.10 # IP 地址 netmask 255.255.255.0 # 子网掩码 gateway 192.168.1.1 # 网关 </span>
重启网络 生效配置
[plain]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
/etc/init.d/networking restart
<span style="font-size:12px;">/etc/init.d/networking restart</span>
/etc/hosts 配置
[plain]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
127.0.0.1 localhost
127.0.1.1 zbq-pc
192.168.157.136 zbq-pc
192.168.157.151 itms-server
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
<span style="font-size:12px;">127.0.0.1 localhost 127.0.1.1 zbq-pc 192.168.157.136 zbq-pc 192.168.157.151 itms-server # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters</span>
hostname 修改 /etc/hostname
SUSE11
cat /etc/udev/rules.d/70-persistent-net.rules 查看MAC
修改 /etc/sysconfig/network/ifcfg-eth0
[plain]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
BOOTPROTO='dhcp'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR=''
MTU=''
NAME='82545EM Gigabit Ethernet Controller (Copper)'
NETMASK=''
NETWORK=''
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'
<span style="font-size:12px;">BOOTPROTO='dhcp' BROADCAST='' ETHTOOL_OPTIONS='' IPADDR='' MTU='' NAME='82545EM Gigabit Ethernet Controller (Copper)' NETMASK='' NETWORK='' REMOTE_IPADDR='' STARTMODE='auto' USERCONTROL='no'</span>
重启网络
[plain]view plaincopyprint?
![](https://code.csdn.net/assets/CODE_ico.png)
/etc/init.d/network restart
<span style="font-size:12px;">/etc/init.d/network restart</span>
修改hostname:/etc/HOSTNAME
相关文章推荐
- centos&Linux 双网卡双网关的配置方法详解
- 感觉比较全的 linux(CentOS) 配置网卡的 手册
- 感觉比较全的 linux(CentOS) 配置网卡的 手册
- CentOS/Linux 网卡设置 IP地址配置
- linux和CentOS下网卡启动、配置等ifcfg-eth0教程
- CentOS — 配置网卡、FTP、安装AMP
- 基于CentOS的Linux基本网络配置,包括网卡eth0、DNS、Host等
- CentOS 6.5下配置Ceph作为KVM后端存储
- windows & linux (centOS/ubuntu) 下 PostgreSQL安装 python php 连接 PostgreSQL
- Linux系列:CentOS 网卡自动启动、配置等ifcfg-eth0教程
- [转]Ubuntu Linux系统下Gnome桌面快捷键配置&桌面目录
- 在Linux(Ubuntu/openSUSE/CentOS)下配置ASP.NET(Apache + Mono)
- Centos7,Ubuntu14.04多网卡配置bond,将多网卡绑定在一起
- CentOS 5.2,Linux 2.6+ 内核 ,Apache+MySQL+PHP 安装及基本配置过程记录 && 将apache安装为系统服务
- 在Linux(Ubuntu/openSUSE/CentOS)下配置ASP.NET(Apache + Mono)
- centos服务器配置一 网卡配置(linux、网卡自动启动)
- LINUX (UBUNTU) 双网卡多VLAN的Server 配置
- Linux (Ubuntu/CentOS) SNMP配置
- Centos 6.5下配置tgt后端存储为ceph