当前位置:首页 > CN2资讯 > 正文内容

linux remove接口 linux调接口

2天前CN2资讯


linux中接口设置方法

一、           设置接口ip地址

1.      ipv4地址

1)        查看接口配置

命令:

ifconfig            查看所有接口的配置

ifconfig  [接口名]    查看指定接口的配置

例子:

[root@TESTBED1 ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:03:0F:FF:DD:20 

          inet addr:194.168.111.1  Bcast:194.168.111.255  Mask:255.255.255.0

          inet6 addr: fe80::203:fff:feff:dd20/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000

          RX bytes:448747 (438.2 KiB)  TX bytes:421026 (411.1 KiB)

          Interrupt:11 Base address:0xe000

 

eth1      Link encap:Ethernet  HWaddr 00:1E:58:46:3D:44 

          inet addr:2.0.0.2  Bcast:2.0.0.255  Mask:255.255.255.0

          inet6                                         

          RX bytes:15897 (15.5 KiB)  TX bytes:69071 (67.4 KiB)

          Interrupt:10

2)        配置接口地址

命令:

ifconfig  [接口名]  [ip地址] 设定接口地址,掩码根据ip地址自动计算出来的。

ifconfig  [接口名]  [ip地址]  netmask  [掩码] 设定接口的地址和掩码

例子:

[root@TESTBED1 ~]# ifconfig eth1 3.0.0.1

[root@TESTBED1 ~]# ifconfig eth1

eth1      Link encap:Ethernet  HWaddr 00:1E:58:46:3D:44 

          inet addr:3.0.0.1  Bcast:3.255.255.255  Mask:255.0.0.0

          inet6 addr: fe80::21e:58ff:fe46:3d44/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000

          RX bytes:15897 (15.5 KiB)  TX bytes:73080 (71.3 KiB)

          Interrupt:10

 

[root@TESTBED1 ~]# ifconfig eth1 3.0.0.1 netmask 255.255.255.0

[root@TESTBED1 ~]# ifconfig eth1

eth1      Link encap:Ethernet  HWaddr 00:1E:58:46:3D:44 

          inet addr:3.0.0.1  Bcast:3.0.0.255  Mask:255.255.255.0

          inet6 addr: fe80::21e:58ff:fe46:3d44/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000

          RX bytes:15897 (15.5 KiB)  TX bytes:76883 (75.0 KiB)

          Interrupt:10

3)        配置接口多个地址

命令:

ifconfig  [接口名]:[子接口数字]  [ip地址]  netmask  [掩码]

说明:

相当于配置多个子接口,每个子接口一个ip地址。

例子:

[root@TESTBED1 ~]# ifconfig eth1:1 1.0.0.1 netmask 255.255.254.0

[root@TESTBED1 ~]# ifconfig eth1:1

eth1:1    Link encap:Ethernet  HWaddr 00:1E:58:46:3D:44 

          inet addr:1.0.0.1  Bcast:1.0.1.255  Mask:255.255.254.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Interrupt:10

4)        删除接口地址

命令:

ifconfig  [接口名]  down

说明:

该命令只是将接口协议down掉,物理连接并未down掉。执行这条命令后,该接口的物理连接指示灯仍然是亮的。

例子:

[root@TESTBED1 ~]# ifconfig eth1:1 down

[root@TESTBED1 ~]# ifconfig eth1:1

eth1:1    Link encap:Ethernet  HWaddr 00:1E:58:46:3D:44 

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Interrupt:10

2.      ipv6地址

1)        增加接口地址

命令:

ifconfig  [接口名]  add  [ipv6地址/掩码]

说明:

Ipv6的接口可以配置多个地址,这里就不需要像ipv4一样配置多个接口了,增加接口地址只需要再次执行该命令。命令中,掩码值不填默认为0;该命令同时也支持地址为ipv4的地址,如果你输入ifconfig eth1 add 6.0.0.1,和你输入ifconfig eth1:0  6.0.0.1执行的效果是一样的。

例子:

[root@TESTBED1 ~]# ifconfig eth1 add 6::1

[root@TESTBED1 ~]# ifconfig eth1 add 3::1/96

[root@TESTBED1 ~]# ifconfig eth1

eth1      Link encap:Ethernet  HWaddr 00:1E:58:46:3D:44 

          inet addr:3.0.0.1  Bcast:255.255.255.159  Mask:255.255.255.0

          inet6 addr: 3::1/96 Scope:Global

          inet6 addr: 6::1/0 Scope:Global

          inet6 addr: fe80::21e:58ff:fe46:3d44/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000

          RX bytes:16077 (15.7 KiB)  TX bytes:103526 (101.0 KiB)

          Interrupt:10

2)        删除接口地址

命令:

ifconfig  del  [ipv6地址/掩码],

说明:

掩码值默认为0

例子:

[root@TESTBED1 ~]# ifconfig eth1 del 3::1/96

[root@TESTBED1 ~]# ifconfig eth1

eth1      Link encap:Ethernet  HWaddr 00:1E:58:46:3D:44 

          inet addr:3.0.0.1  Bcast:255.255.255.159  Mask:255.255.255.0

          inet6 addr: 6::1/0 Scope:Global

          inet6 addr: fe80::21e:58ff:fe46:3d44/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000

          RX bytes:16077 (15.7 KiB)  TX bytes:105894 (103.4 KiB)

          Interrupt:10

[root@TESTBED1 ~]# ifconfig eth1 del 6::1

[root@TESTBED1 ~]# ifconfig eth1

eth1      Link encap:Ethernet  HWaddr 00:1E:58:46:3D:44 

          inet addr:3.0.0.1  Bcast:255.255.255.159  Mask:255.255.255.0

          inet6 addr: fe80::21e:58ff:fe46:3d44/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000

          RX bytes:16077 (15.7 KiB)  TX bytes:107448 (104.9 KiB)

          Interrupt:10

3.      配置vlan接口(接口发报文都带tag)

1)        配置地址:

命令:

vconfig  add  [接口名]  [vlan号]

ifconfig  [接口名].[vlan号]  [ip地址]

说明:

第一个命令增加一个vlan子接口,第二个命令配置该子接口的地址,配置好后该子接口发出的报文都会带上配置的tag

例子:

配置接口属于vlan2带tag,ip地址为3.0.0.2

[root@TESTBED1 ~]# vconfig add eth1 2

Added VLAN with VID == 2 to IF -:eth1:-

[root@TESTBED1 ~]# ifconfig eth1.2 3.0.0.2 netmask 255.255.0.0

[root@TESTBED1 ~]# ifconfig eth1.2

eth1.2    Link encap:Ethernet  HWaddr 00:1E:58:46:3D:44 

          inet addr:3.0.0.2  Bcast:3.0.255.255  Mask:255.255.0.0

          inet6 addr: fe80::21e:58ff:fe46:3d44/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 b)  TX bytes:4580 (4.4 KiB)

2)        删除地址:

命令:

vconfig rem [接口名].[vlan号]

例子:

[root@TESTBED1 ~]# vconfig rem eth1.2

Removed VLAN -:eth1.2:-

[root@TESTBED1 ~]# ifconfig eth1.2

eth1.2: error fetching interface information: Device not found

二、           配置路由

1.      添加到主机路由

命令:

route  add  –host  [ip地址]  dev  [接口名]

或者

route  add  –host  [ip地址]   gw  [下一跳地址]

例子:

[root@TESTBED1 ~]# route add -host 100.0.0.1 dev eth1

[root@TESTBED1 ~]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

100.0.0.1       *               255.255.255.255 UH    0      0        0 eth1

194.168.111.0   *               255.255.255.0   U     0      0        0 eth0

link-local      *               255.255.0.0     U     0      0        0 eth1

1.0.0.0         *               255.0.0.0       U     0      0        0 eth1

 

[root@TESTBED1 ~]# route add -host 100.0.0.1 gw 1.0.0.2

[root@TESTBED1 ~]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

100.0.0.1       1.0.0.2         255.255.255.255 UGH   0      0        0 eth1

100.0.0.1       *               255.255.255.255 UH    0      0        0 eth1

194.168.111.0   *               255.255.255.0   U     0      0        0 eth0

link-local      *               255.255.0.0     U     0      0        0 eth1

1.0.0.0         *               255.0.0.0       U     0      0        0 eth1

[root@TESTBED1 ~]# 

2.      添加到网络的路由

命令:

route  add  -net  [网段]  netmask  [掩码]  gw  [下一条地址]

或者:

route  add  -net  [网段]  netmask  [掩码]  dev  [接口名]

或者:

route  add  -net  [网段]/[掩码位数]  dev  [接口名]

例子:

[root@TESTBED1 ~]# route add -net 200.1.1.0 netmask 255.255.255.0 gw 1.0.0.2 

[root@TESTBED1 ~]#  eth1     

[root@TESTBED1 ~]# route add -net 201.1.1.0/24 dev eth1

[root@TESTBED1 ~]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

200.1.1.0       *               255.255.255.0   U     0      0        0 eth1

200.1.1.0       1.0.0.2         255.255.255.0   UG    0      0        0 eth1

201.1.1.0       *               255.255.255.0   U     0      0        0 eth1

194.168.111.0   *               255.255.255.0   U     0      0        0 eth0

link-local      *               255.255.0.0     U     0      0        0 eth1

1.0.0.0         *               255.0.0.0       U     0      0        0 eth1 

3.      添加默认网关

命令:

route  add  default  gw  [下一跳地址]

例子:

[root@TESTBED1 ~]# route add default gw 1.0.0.3

[root@TESTBED1 ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

194.168.111.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0

1.0.0.0         0.0.0.0         255.0.0.0       U     0      0        0 eth1

0.0.0.0         1.0.0.3         0.0.0.0         UG    0      0        0 eth1

4.      删除路由

命令:

route  del  [增加路由时添加的选项]

例子:

删除配置的默认路由

[root@TESTBED1 ~]#    

[root@TESTBED1 ~]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

194.168.111.0   *               255.255.255.0   U     0      0        0 eth0

1.0.0.0         *               255.0.0.0       U     0      0        0 eth1

5.      增加ipv6路由

命令:

route  -A  inet  add  [ipv6地址/掩码]  gw  [下一跳地址]

6.      删除ipv6路由

route  -A  inet  del  [ipv6地址/掩码]  gw  [下一跳地址]

    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/25744.html

    分享给朋友:

    “linux remove接口 linux调接口” 的相关文章

    测试IP地址的重要性与常用工具推荐

    在网络管理中,测试IP地址的重要性不可忽视。每当我遇到网络问题,测试IP地址就成了第一步。了解IP地址的状态和性能,不仅能帮助我找到问题所在,还能快速解决网络故障。这就像是医生给病人做检查,只有找出病因,才能对症下药。 我们在进行网络操作时,IP地址就像每台设备的身份名片。借助一些功能强大的工具,我...

    VPS流媒体解锁测试:确保顺畅访问全球流媒体内容

    在如今的互联网时代,流媒体已经成为我们日常生活中不可或缺的一部分。无论是观看热门电视剧,还是播放最新的音乐视频,流媒体服务的便捷性吸引了无数用户。然而,涉及不同地区提供的内容时,依然存在一些区域限制。这时,VPS(虚拟专用服务器)流媒体解锁技术的重要性便不言而喻。 VPS流媒体解锁是指通过虚拟专用服...

    hncloud:助力企业数字化转型的云计算服务提供商

    在数字化浪潮席卷全球的今天,hncloud(华纳云)应运而生,成为一家备受瞩目的全球数据中心基础服务提供商。隶属于香港联合通讯国际有限公司的hncloud,凭借其在行业中的深厚积淀和技术实力,逐渐发展成为一颗闪耀于云计算领域的明星。作为APNIC和ARIN的会员单位,hncloud自有ASN号,为用...

    选择台湾VPS的优势与实用技巧分析

    在当今互联网迅速发展的时代,虚拟专用服务器(VPS)成为了众多企业和个人不二的选择。台湾VPS作为一个相对新兴的产品,凭借自己独特的地理位置和优异的技术性能,逐渐在市场上占据了一席之地。身为个人或企业,在选择服务器时,了解台湾VPS的基本概念及其优势无疑是一个明智的开始。 什么是VPS? VPS,即...

    如何有效使用WP Rocket插件提升WordPress网站性能

    WP Rocket是一个强大的高级WordPress缓存插件,它的使用对于提升网站的速度和性能起着至关重要的作用。如今,网站的加载速度对于用户体验和SEO排名都有着重要的影响。WP Rocket通过一系列功能和设置,帮助用户轻松优化自己的网站,进而增加访问量和客户满意度。 在使用WP Rocket插...

    如何选择合适的IP站及其运作原理

    IP站的运作原理 在探讨IP站的运作原理之前,首先需要明确什么是IP站。简单来说,IP站是一种特殊的网络服务,它利用互联网协议(IP)提供不同的网络功能和服务。每个IP站都与一个或多个IP地址相连,能够用来访问信息、数据或应用程序。在我的网络体验中,无论是个人使用还是企业应用,IP站总是扮演着至关重...