此文参考:

1.网络文章,但最后发现源头是在《鸟哥私房菜》,再次感谢原作者;

2.工作中跟同事讨论,自己尝试。

本人水平有限,如有错误,请大家指正,谢谢。

一 网络参数设置命令

1.ifconfig :查询、设置网卡与IP网段等相关参数

1.1 man手册定义

DESCRIPTIONIfconfig  is used to configure the kernel-resident network interfaces.  It is used at boot time to set upinterfaces as necessary.  After that, it is usually only needed when debugging or when system  tuning  isneeded.If  no arguments are given, ifconfig displays the status of the currently active interfaces.  If a singleinterface argument is given, it displays the status of the given interface only; if a single -a  argumentis  given,  it displays the status of all interfaces, even those that are down.  Otherwise, it configuresan interface.

简译: ifconfig 习惯用于配置kernel-resident 网络接口,一般在启动时设置必要的接口。也用于debug和系统调试。

如果没有参数 会列出当前激活(up status)的网络接口

如果接一个网络接口参数(ifconfig eth0),会输出该接口的配置

如果后面参数是-a, 会输出所有的网络接口(up 和down staus的网络接口)

1.2 命令输出简述

[root@test_1 net]# ifconfig
eth0      Link encap:Ethernet  HWaddr 84:2B:2B:94:F7:7D  inet addr:192.168.2.241  Bcast:192.168.2.255  Mask:255.255.255.0inet6 addr: fe80::862b:2bff:fe94:f77d/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1RX packets:1546524 errors:0 dropped:0 overruns:0 frame:0TX packets:1652650 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:754067360 (719.1 MiB)  TX bytes:1474728958 (1.3 GiB)Interrupt:18 eth0:1    Link encap:Ethernet  HWaddr 84:2B:2B:94:F7:7D  inet addr:192.168.2.242  Bcast:192.168.2.255  Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1Interrupt:18 eth0:2    Link encap:Ethernet  HWaddr 84:2B:2B:94:F7:7D  inet addr:192.168.2.243  Bcast:192.168.2.255  Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1Interrupt:18 lo        Link encap:Local Loopback  inet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:16436  Metric:1RX packets:594 errors:0 dropped:0 overruns:0 frame:0TX packets:594 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:51885 (50.6 KiB)  TX bytes:51885 (50.6 KiB)

。eth0:网卡的代号,也有lo这个loopback。

· HWaddr:网卡的硬件地址,习惯称为MAC。

· inet addr:IPv4的IP地址,后续的Bcase、Mask分别代表的是Broadcast与Netmask。

· inet6 addr:是IPv6的版本的IP,我们没有使用,所以略过。

· RX:那一行代表的是网络由启动到目前为止的数据包接收情况,packets代表数据包数、errors代表数据包发生错误的数量、dropped代表数据包由于有问题而遭丢弃的数量等。

· TX:与RX相反,为网络由启动到目前为止的传送情况。

· collisions:代表数据包碰撞的情况,如果发生太多次,表示你的网络状况不太好。

· txqueuelen:代表用来传输数据的缓冲区的储存长度。

· RX Bytes、TX Bytes:总传送、接收的字节总量。

· Interrupt、Memory:网卡硬件的数据,IRQ岔断与内存地址。

通过观察上述的资料,大致上可以了解到你的网络情况,尤其是RX、TX内的error数量,以及是否发生严重的collision情况,都是需要注意的。

1.3应用

1.3.1 下面是我给一个网卡配置多个ip地址用的命令

ifconfig eth0:1 192.168.2.242 netmask 255.255.255.0 up &
ifconfig eth0:2 192.168.2.243 netmask 255.255.255.0 up &

PS: 这种配置子系统重启后,会失去,若想系统重启后不丢失,解决方法一:

将该命令添加到rc.local 里 如下后两行

[devtac@test_1 network-scripts]$ more /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.touch /var/lock/subsys/local
xl2tpd -c /etc/xl2tpd.conf -D &
ifconfig eth0:1 192.168.2.242 netmask 255.255.255.0 up &
ifconfig eth0:2 192.168.2.243 netmask 255.255.255.0 up &

2. ifup ifdown

2.1 简述:man 手册里说的很清楚,如下

       The  ifup  and  ifdown commands may be used to configure (or, respec- tively, deconfigure) network inter-faces based on interface definitions in  the  files  /etc/sysconfig/network  and  /etc/sysconfig/network-scripts/ifcfg-<configuration>These scripts take one argument normally: the name of the configuration (e.g. eth0). They are called witha second argument of "boot" during the boot sequence so that devices that are not meant to be brought  upon boot (ONBOOT=no, see below) can be ignored at that time.

简译:ifup 和ifdown 命令 用于配置位于/etc/sysconfig/network 和/etc/sysconfig/network-scripts/ifcfg-<configuration> 已经配置过的网卡接口文件 如下两个配置文件

[devtac@test_1 network-scripts]$ pwd
/etc/sysconfig/network-scripts
[devtac@test_1 network-scripts]$ ll
总用量 204
-rw-r--r--. 1 root root   276 8月  26 14:35 ifcfg-eth0
-rw-r--r--. 1 root root   254 1月   9 2013 ifcfg-lo

通常,该命令会接一个参数。

PS:ifup ifdown 所在位置如下,有兴趣的可以分析下这两个脚本。

[devtac@test_1 network-scripts]$ pwd
/etc/sysconfig/network-scripts
[devtac@test_1 network-scripts]$ ll ifup ifdown
lrwxrwxrwx. 1 root root 20 8月  26 14:40 ifdown -> ../../../sbin/ifdown
lrwxrwxrwx. 1 root root 18 8月  26 14:40 ifup -> ../../../sbin/ifup

2.2脚本阅读。。。需要时间~~~或者另开。

2.3使用  注:下面例子里因为eth0 已经启动了。大家若是ssh 连接到服务器,请审议ifdown ,网卡停了,就无法连上主机了。。。。

[root@test_1 ~]# ifup eth0
活跃连接状态:激活的
活跃连接路径:/org/freedesktop/NetworkManager/ActiveConnection/1

3.route

3.1 man 手册定义

DESCRIPTIONRoute manipulates the kernel’s IP routing tables.  Its primary use is to set up static routes to specifichosts or networks via an interface after it has been configured with the ifconfig(8) program.When  the  add  or del options are used, route modifies the routing tables.  Without these options, routedisplays the current contents of the routing tables.

简译:Route 用于操作 内核IP的路由表。它的主要作用是设置静态路由,当访问某个特定主机或者网段时通过路由配置的主机 访问。

当后面接add 或者del 命令时 ,修改路由规则;没有add 或者del 时 列出当前路由表。

3.2 命令参数详解

[root@linux ~]# route [-nee]
[root@linux ~]# route add [-net|-host] [网段或主机] netmask [mask] [gw|dev]
[root@linux ~]# route del [-net|-host] [网段或主机] netmask [mask] [gw|dev]
观察的参数:-n,不要使用通信协议或主机名称,直接使用 IP 或 Port Number;-ee,使用更详细的信息来显示;
增加 (add) 与删除 (del) 路由的相关参数;-net,表示后面接的路由为一个网段;-host,表示后面接的为连接到单台主机的路由;Netmask,与网段有关,可以设置 netmask 决定网段的大小;Gw,gateway 的简写,后续接的是 IP 的数值,与 dev 不同;Dev,如果只是要指定由哪一块网卡联机出去,则使用这个设置,后面接 eth0 等。

3.3 route 命令输出参数解释

[root@test_1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0
192.168.200.0   192.168.2.1     255.255.255.0   UG    0      0        0 eth0
192.178.200.0   192.168.2.1     255.255.255.0   UG    0      0        0 eth0
0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
[root@test_1 ~]#
[root@test_1 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     *               255.255.255.0   U     1      0        0 eth0
192.168.200.0   192.168.2.1     255.255.255.0   UG    0      0        0 eth0
192.178.200.0   192.168.2.1     255.255.255.0   UG    0      0        0 eth0
default         192.168.2.1     0.0.0.0         UG    0      0        0 eth0

· Destination、Genmask:这两个术语就分别是Network与Netmask了。所以这两个东西就组合成为一个完整的网段了。

· Gateway:该网段是通过哪个Gateway连接出去的?如果显示0.0.0.0表示该路由是直接由本机传送,亦即可以通过局域网的MAC直接传输;如果有显示IP的话,表示该路由需要经过路由器(网关)的帮忙才能够传送出去。

· Flags:总共有多个标记,代表的意义如下。

Ø U(route is up):该路由是启动的。

Ø H(target is a host):目标是一台主机(IP)而非网段。

Ø G(use gateway):需要通过外部的主机来传递数据包。

Ø R(reinstate route for dynamic routing):使用动态路由时,恢复路由信息的标记。

Ø D(dynamically installed by daemon or redirect):已经由服务器或转port功能设置为动态路由。

Ø M(modified from routing daemon or redirect):路由已经被修改了。

Ø!(reject route):这个路由将不会被接受(用来阻止不安全的网段)。

· Iface:这个路由传递数据包的接口。

3.4 route add del 示例

[root@test_1 ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 * 255.255.255.0 U 1 0 0 eth0
192.168.200.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
192.178.200.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
default 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
[root@test_1 ~]# route del -net 192.168.200.0 netmask 255.255.255.0 gw 192.168.2.1 dev eth0
[root@test_1 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
192.178.200.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
[root@test_1 ~]# route add -net 192.168.200.0 netmask 255.255.255.0 gw 192.168.2.1 dev eth0
[root@test_1 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
192.168.200.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
192.178.200.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0

问题:目前我用vpn 访问google,但是如何设置route ,当我访问非www.google.com 时用原先的网络,而访问

www.google.com 时用vpn?

环境:主机 WIN7

转载于:https://www.cnblogs.com/tacg/p/4128338.html

常用linux 命令 -网络相关相关推荐

  1. 常用linux下网络相关命令

    说明: 以下命令为Linux中常用的网络命令,适用于大多数Linux/Unix系统,少数系统可能会有差异.欢迎大家根据自己日常工作中的使用情况进行补充. 设置网络参数的命令: 手动/自动配置IP参数与 ...

  2. LINUX学习笔记:31个常用LINUX命令和相关解释

    LINUX学习笔记三: 最近在带新同事,是一个刚入行的萌新,对于linux不是很熟悉,问我怎么来学习. 所以今天接着之前的部分,继续分享一些linux学习资料.有需要的点点保存,没有跳过呗.PS:内容 ...

  3. base64 linux_渗透测试常用Linux命令总结

    作为一名网络安全工作者,一说到渗透测试,所有人都会想到Kali Linux,Kali Linux系统是一款预装了许多渗透测试软件的Linux系统,是最常用的一款渗透测试系统工具,既然是一款Linux系 ...

  4. 常用Linux命令:

    常用Linux命令: 文件和目录: # cd /home                        进入 '/home' 目录 # cd ..                           ...

  5. 常用Linux命令及其作用(超详细,带演示)

    常用Linux命令及其作用(超详细,带演示) 文章目录 常用Linux命令及其作用(超详细,带演示) 1. 提前了解 1.1 终端命令格式 1.2 --help 1.3 man command 查询使 ...

  6. 常用LINUX命令汇总

    常用LINUX命令汇总 一.基本命令 bash Bash(GNU Bourne-Again Shell)是许多Linux平台的内定Shell pwd 查看当前所在目录 ls 查看目录内所有文件 cd ...

  7. Linux 学习笔记3 -- 常用 Linux 命令的基本使用

    文章目录 1. 学习 Linux 终端命令的原因 2. 常用 Linux 命令的基本使用 3. 终端实用技巧 3.1 自动补全 3.2 曾经使用过的命令 4. Linux 终端命令格式 5. 查阅命令 ...

  8. linux运维工程师命令,Linux运维工程师的常用Linux命令汇总

    今天小编要跟大家分享的文章是关于Linux运维工程师的常用Linux命令汇总.作为运维人员,这些常用命令不得不会,掌握这些命令,工作上会事半功倍,提供工作效率.下面来和小编一起看一看吧! 一.文件和目 ...

  9. [Linux]Linux打開world、Excel、pdf文檔,常用Linux命令總結

    Linux打開world.Excel.pdf文檔 ---- 常用Linux命令總結 一.在Linux中打開world文檔(需要安裝openoffice) 1.1.打开或编辑.doc .odt等文本文档 ...

最新文章

  1. 高中计算机个人总结怎么写,毕业生自我总结范文
  2. linux的git命令,linux命令实战安装git、配置git、创建仓库、部署项目
  3. 每日一皮:据说PM就是这样忍受你的!
  4. 视频、音频打时间戳的方法及其音视频同步(播放)原理
  5. 什么是DVI光端机?dvi光端机的优势有哪些?
  6. 计算机组装报告文档,计算机组装报告.doc.docx
  7. 《Python Cookbook 3rd》笔记(5.2):打印输出至文件中
  8. esp8266 rtos 开发环境 ubuntu_esp8266/32~资源帖[持续更新]
  9. Unity Shader:用几何着色器实现复联3灭霸的终极大招灰飞烟灭
  10. unity android 原生,unity创建Android原生插件
  11. 如何使用apiPOST进行模拟发送get、post、delete、put请求(支持文件上传)
  12. Mac系统升级node
  13. python:库文件整理
  14. 如何注册ocx文件。。。
  15. photoshop 前端切图基础教程
  16. 颜值评分,图像识别,植物、动物、车型、菜品、logo识别
  17. 市场分析-全球与中国OLED用氧化氘市场现状及未来发展趋势
  18. linux 部署应用服务器,(小白指南)在 Linux 服务器上安装 Nodejs、Nginx 以及部署 Web 应用...
  19. 轮播图和导航栏:Vue和JavaScript分别实现
  20. 打开桌面计算机不显示文件夹,Win10系统怎么让此电脑中的文件夹不显示?

热门文章

  1. Android SurfaceView、TextureView区别
  2. php 时间配置,php 配置正确的时间
  3. extern C和__declspec(dllexport)以及__declspec(dllimport) 和def的简单解析
  4. 长得类似铁甲小宝的机器人_《铁甲小宝》盘点机器人原型,卡布达原来是独角仙...
  5. 短视频脚本怎么写?6个套路
  6. 补题系列 1 最小布线
  7. 【机器学习入门到精通系列】OVR SVMs
  8. 图解网络TCP/IP
  9. 【Java基础快速入门】概述及开发环境搭建
  10. vscode使用方法