此文参考:

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

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

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

一 网络参数设置命令

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

1.1 man手册定义

DESCRIPTION
Ifconfig is used to configure the kernel-resident network interfaces. It is used at boot time to set up
interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is
needed. If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single
interface argument is given, it displays the status of the given interface only; if a single -a argument
is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures
an 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 :2B:2B::F7:7D
inet addr:192.168.2.241 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::862b:2bff:fe94:f77d/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (719.1 MiB) TX bytes: (1.3 GiB)
Interrupt: eth0: Link encap:Ethernet HWaddr :2B:2B::F7:7D
inet addr:192.168.2.242 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
Interrupt: eth0: Link encap:Ethernet HWaddr :2B:2B::F7:7D
inet addr:192.168.2.243 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
Interrupt: lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (50.6 KiB) TX bytes: (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: 192.168.2.242 netmask 255.255.255.0 up &
ifconfig eth0: 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: 192.168.2.242 netmask 255.255.255.0 up &
ifconfig eth0: 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 with
a second argument of "boot" during the boot sequence so that devices that are not meant to be brought up
on 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
总用量
-rw-r--r--. root root 8月 : ifcfg-eth0
-rw-r--r--. root root 1月 ifcfg-lo

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

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

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

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

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

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

3.route

3.1 man 手册定义

DESCRIPTION
Route manipulates the kernel’s IP routing tables. Its primary use is to set up static routes to specific
hosts or networks via an interface after it has been configured with the ifconfig() program. When the add or del options are used, route modifies the routing tables. Without these options, route
displays 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 eth0
192.168.200.0 192.168.2.1 255.255.255.0 UG eth0
192.178.200.0 192.168.2.1 255.255.255.0 UG eth0
0.0.0.0 192.168.2.1 0.0.0.0 UG 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 eth0
192.168.200.0 192.168.2.1 255.255.255.0 UG eth0
192.178.200.0 192.168.2.1 255.255.255.0 UG eth0
default 192.168.2.1 0.0.0.0 UG 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

常用linux 命令 -网络相关的更多相关文章

  1. # 常用linux 命令和相关问题解决

    最近试着自己部署了服务器,在unbantu的环境下 学习了很多新知识 也遇到了很多问题,现在腾出手了,总结一下 常用Linux命令 目录操作 pwd: 查看当前路径 cd: 移动 cd .. : 返回 ...

  2. 常用linux 命令 -字符串相关

    参考网络文章,个人工作总结 题记:一般对字符串的操作有以下几种:求长度,截取字符串,拼接字符串,找字符串中某个字符的索引 1 expr 命令 1.1 定义 man 手册 Print the value ...

  3. 77个常用Linux命令和工具

    77个常用Linux命令和工具 Linux管理员不能单靠GUI图形界面吃饭.这就是我们编辑这篇最实用Linux命令手册的原因.这个指南是特别为Linux管理员和系统管理员 设计的,汇集了最有用的一些工 ...

  4. Linux命令网络命令之netstat

    Linux命令网络命令之netstat 这一年感觉到技术上成长到了一个瓶颈.可能是感觉自己学的东西足够应付目前的工作了,因此精神上就产生了懈怠,不思进取.到了一个技术氛围不错的公司,有许多专业能力很不 ...

  5. F4NNIU 的常用 Linux 命令(2019-08-24)

    目录 F4NNIU 的常用 Linux 命令 停止防火墙 查看 IP 址 启动 deepin 的桌面 查看当前时区 查看 CPU 和内存信息 用户相关 日志 F4NNIU 的常用 Linux 命令 记 ...

  6. 常用Linux命令小结

    常用Linux命令小结 Linux下有很多常用的很有用的命令,这种命令用的多了就熟了,对于我来说,如果长时间没有用的话,就容易忘记.当然,可以到时候用man命令查看帮助,但是,到时候查找的话未免有些临 ...

  7. 常用Linux命令笔记

    任何脱离业务的架构都是耍流氓 只记录实际常用的Linux命令 常用Linux命令 查找安装路径: whereis nginx 查询nginx进程: ps aux|grep nginx 查看 CentO ...

  8. 【Linux基础】常用Linux命令: cd, cp, ls, mkdir, mv, rm, su, uname

    常用Linux命令:cd, cp, ls, mkdir, mv, rm, su, uname cd命令:切换当前工作目录至 dirName(目录参数) 其中 dirName 可为绝对路径或相对路径.若 ...

  9. 01_常用 Linux 命令的基本使用

    01. 学习 Linux 终端命令的原因 Linux 刚面世时并没有图形界面,所有的操作全靠命令完成,如 磁盘操作.文件存取.目录操作.进程管理.文件权限 设定等 在职场中,大量的 服务器维护工作 都 ...

随机推荐

  1. 同步降压DC-DC转换IC——XC9264

    设计一个12V转3.3V,输出电流30mA的电源电路,由于项目对转化效率要求较高,所以不能采用低压差线性稳压LDO的方案.经过对比,TOREX的XC9264效率在此转化条件下效率可做到85%以上,比M ...

  2. Python学习进程

    1周第1天 主要是变量的学习(11月8日) 1.1 python安装(win和linux下)1.2 ipython安装及使用1.3 变量的定义1.4 变量赋值1.5 运算符(赋值.算术.关系.逻辑)1 ...

  3. 大众点评cat系统的搭建笔记

    项目地址:https://github.com/dianping/cat 编译步骤: 这个项目比较另类,把编译需要的jar包,单独放在git分支mvn-repo里了,而且官方文档里给了一个错误的命令提 ...

  4. [LeetCode] Mini Parser 迷你解析器

    Given a nested list of integers represented as a string, implement a parser to deserialize it. Each ...

  5. 【前端积累】JavascriptUtil 字符串部分

    //计算字符串长度 String.prototype.strLen = function() { var len = 0; for (var i = 0; i < this.length; i+ ...

  6. 请写一个php函数,可以接受任意数量的参数

    请写一个php函数,可以接受任意数量的参数 这是一道面试题.怎么写这个函数呢? function fun(......) { } ----------------------------------- ...

  7. js-读取复选框

    js: var obj = document.getElementsByName("yk"); var check_val = []; for(k in obj){ if(obj[ ...

  8. 两种遍历list

    li=[[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]]s=0for i in range(0,5): for j in ran ...

  9. js文件中函数前加分号和感叹号是什么意思?

    本文转自:http://blog.csdn.net/h_o_w_e/article/details/51388500 !function(){}();   !有什么用? 从语法上来开,JavaScri ...

  10. ActiveMQ_Mqtt的TCP丢包

    现象 Mqtt Consumer应该收到的消息少于预期,登录ActiveMQ的管理页面里的Topics,查看Messages Enqueued发现同样少于理应接收的数量. 定位问题 怀疑是TCP丢包, ...