linux中修改vlan的ip地址,RHEL在VLAN Trunk模式下的IP地址配置

今天拿到客户两笼刀片机,进行RHEL6U3系统的安装操作,打算安装完第一台刀片之后,将其配置成KICKSTART服务器对其他刀片进行网络安装。

然而,安装完第一片刀之后,对其进行IP的设置。

1. 首先查看有多少个网卡

[iyunv@blog01 ~]# ip a

1: lo: mtu 16436 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

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0: mtu 1500 qdisc mq state UP qlen 1000

link/ether 38:ea:a7:a1:fd:66 brd ff:ff:ff:ff:ff:ff

inet6 fe80::3aea:a7ff:fea1:fd66/64 scope link

valid_lft forever preferred_lft forever

3: eth1: mtu 1500 qdisc noop state DOWN qlen 1000

link/ether 38:ea:a7:a1:fd:6a brd ff:ff:ff:ff:ff:ff

4: eth2: mtu 1500 qdisc noop state DOWN qlen 1000

link/ether 38:ea:a7:a1:fd:68 brd ff:ff:ff:ff:ff:ff

5: eth3: mtu 1500 qdisc noop state DOWN qlen 1000

link/ether 38:ea:a7:a1:fd:6c brd ff:ff:ff:ff:ff:ff

6: eth4: mtu 1500 qdisc noop state DOWN qlen 1000

link/ether 38:ea:a7:a1:fd:69 brd ff:ff:ff:ff:ff:ff

7: eth5: mtu 1500 qdisc noop state DOWN qlen 1000

link/ether 38:ea:a7:a1:fd:6d brd ff:ff:ff:ff:ff:ff

8: eth6: mtu 1500 qdisc noop state DOWN qlen 1000

link/ether 38:ea:a7:a1:fd:6e brd ff:ff:ff:ff:ff:ff

9: eth7: mtu 1500 qdisc noop state DOWN qlen 1000

link/ether 38:ea:a7:a1:fd:72 brd ff:ff:ff:ff:ff:ff

2. 查看哪些网卡是连接正常的

[iyunv@blog01 ~]# for i  in `seq 0 7`

> do

> res=`ethtool eth$i |grep Link |awk -F: '{print $2}'`

> echo "eth$i  Link $res"

> done

eth0  Link  yes

eth1  Link  yes

eth2  Link  no

eth3  Link  no

eth4  Link  no

eth5  Link  no

eth6  Link  no

eth7  Link  no

3. 可以看出eth0,eth1是连接成功的

4. 对eth0配置IP地址

从客户获得的IP设置范围是10.196.28.0/24 ,该网段端口被设置成了Trunk模式。

5.手动将eth0加入vlan id为528的VLAN,并配置IP

[iyunv@blog01 ~]# vconfig  add eth0 528

[iyunv@blog01 ~]# ifconfig eth0.528 10.196.28.43 netmask 255.255.255.0

[iyunv@blog01 ~]# ping  -W1 -c2 10.196.28.254

PING 10.196.28.254 (10.196.28.254) 56(84) bytes of data.

64 bytes from 10.196.28.254: icmp_seq=1 ttl=255 time=1.14 ms

64 bytes from 10.196.28.254: icmp_seq=2 ttl=255 time=1.15 ms

--- 10.196.28.254 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1002ms

rtt min/avg/max/mdev = 1.149/1.154/1.159/0.005 ms

6.写入网卡配置文件

为了使得系统重启后,IP配置仍旧生效,写入系统配置文件

另外本机需要作为KVM虚拟化平台,故需要创建桥接设备br0

[iyunv@blog01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

TYPE=Ethernet

BOOTPROTO=none

[iyunv@blog01 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0.528

DEVICE=eth0.528

ONBOOT=yes

BOOTPROTO=none

VLAN=yes

TYPE=Ethernet

BRIDGE=br0

[iyunv@blog01 ~]#cat /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE=br0

ONBOOT=yes

BOOTPROTO=none

TYPE=Bridge

IPADDR=10.196.28.43

NETMASK=255.255.255.0

GATEWAY=10.196.28.254

7.重新启动网络服务,查看最终网卡配置信息

[iyunv@blog01 ~ ]# service network restart

[iyunv@blog01  ~]# cat /proc/net/vlan/config

VLAN Dev name     | VLAN ID

Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD

eth0.528       | 528  | eth0

[iyunv@SJC42KVM01 ~]# brctl  show

bridge name    bridge id        STP enabled    interfaces

br0        8000.38eaa7a1fd66    no        eth0.528

[iyunv@SJC42KVM01 ~]# ifconfig  eth0

eth0      Link encap:Ethernet  HWaddr 38:EA:A7:A1:FD:66

inet6 addr: fe80::3aea:a7ff:fea1:fd66/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:14600981 errors:0 dropped:0 overruns:0 frame:0

TX packets:16880 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:1175506152 (1.0 GiB)  TX bytes:4080056 (3.8 MiB)

[iyunv@blog01  ~]# ifconfig  eth0.528

eth0.528  Link encap:Ethernet  HWaddr 38:EA:A7:A1:FD:66

inet6 addr: fe80::3aea:a7ff:fea1:fd66/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:600 errors:0 dropped:0 overruns:0 frame:0

TX packets:313 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:66715 (65.1 KiB)  TX bytes:57925 (56.5 KiB)

[iyunv@blog01 ~]# ifconfig  br0

br0       Link encap:Ethernet  HWaddr 38:EA:A7:A1:FD:66

inet addr:10.196.28.43  Bcast:10.196.28.255  Mask:255.255.255.0

inet6 addr: fe80::3aea:a7ff:fea1:fd66/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:549 errors:0 dropped:0 overruns:0 frame:0

TX packets:345 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:63581 (62.0 KiB)  TX bytes:64296 (62.7 KiB)

8.测试网络连接是否通畅

[iyunv@blog01 ~]# ping -W1 -c2  10.196.28.254

PING 10.196.28.254 (10.196.28.254) 56(84) bytes of data.

64 bytes from 10.196.28.254: icmp_seq=1 ttl=255 time=1.31 ms

64 bytes from 10.196.28.254: icmp_seq=2 ttl=255 time=0.907 ms

--- 10.196.28.254 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1002ms

rtt min/avg/max/mdev = 0.907/1.108/1.310/0.204 ms

[iyunv@blog01 ~]# ping -W1 -c2  10.192.28.254

PING 10.192.28.254 (10.192.28.254) 56(84) bytes of data.

64 bytes from 10.192.28.254: icmp_seq=1 ttl=249 time=2.63 ms

64 bytes from 10.192.28.254: icmp_seq=2 ttl=249 time=2.78 ms

--- 10.192.28.254 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1004ms

rtt min/avg/max/mdev = 2.635/2.709/2.784/0.090 ms

配置完成!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值