常用linux 命令 -网络相关
此文参考:
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 命令 -网络相关的更多相关文章
- # 常用linux 命令和相关问题解决
最近试着自己部署了服务器,在unbantu的环境下 学习了很多新知识 也遇到了很多问题,现在腾出手了,总结一下 常用Linux命令 目录操作 pwd: 查看当前路径 cd: 移动 cd .. : 返回 ...
- 常用linux 命令 -字符串相关
参考网络文章,个人工作总结 题记:一般对字符串的操作有以下几种:求长度,截取字符串,拼接字符串,找字符串中某个字符的索引 1 expr 命令 1.1 定义 man 手册 Print the value ...
- 77个常用Linux命令和工具
77个常用Linux命令和工具 Linux管理员不能单靠GUI图形界面吃饭.这就是我们编辑这篇最实用Linux命令手册的原因.这个指南是特别为Linux管理员和系统管理员 设计的,汇集了最有用的一些工 ...
- Linux命令网络命令之netstat
Linux命令网络命令之netstat 这一年感觉到技术上成长到了一个瓶颈.可能是感觉自己学的东西足够应付目前的工作了,因此精神上就产生了懈怠,不思进取.到了一个技术氛围不错的公司,有许多专业能力很不 ...
- F4NNIU 的常用 Linux 命令(2019-08-24)
目录 F4NNIU 的常用 Linux 命令 停止防火墙 查看 IP 址 启动 deepin 的桌面 查看当前时区 查看 CPU 和内存信息 用户相关 日志 F4NNIU 的常用 Linux 命令 记 ...
- 常用Linux命令小结
常用Linux命令小结 Linux下有很多常用的很有用的命令,这种命令用的多了就熟了,对于我来说,如果长时间没有用的话,就容易忘记.当然,可以到时候用man命令查看帮助,但是,到时候查找的话未免有些临 ...
- 常用Linux命令笔记
任何脱离业务的架构都是耍流氓 只记录实际常用的Linux命令 常用Linux命令 查找安装路径: whereis nginx 查询nginx进程: ps aux|grep nginx 查看 CentO ...
- 【Linux基础】常用Linux命令: cd, cp, ls, mkdir, mv, rm, su, uname
常用Linux命令:cd, cp, ls, mkdir, mv, rm, su, uname cd命令:切换当前工作目录至 dirName(目录参数) 其中 dirName 可为绝对路径或相对路径.若 ...
- 01_常用 Linux 命令的基本使用
01. 学习 Linux 终端命令的原因 Linux 刚面世时并没有图形界面,所有的操作全靠命令完成,如 磁盘操作.文件存取.目录操作.进程管理.文件权限 设定等 在职场中,大量的 服务器维护工作 都 ...
随机推荐
- CANopen学习——协议栈
协议,是双方都提前商量好的通讯约定. 例如:发送1代表灯亮,发送0代表灯灭. 但由于只是单bit的0和1在通信时,抗干扰太弱,且多种控制时不能区分,此时扩展一下协议. 例如: 头 地址 ...
- [bzoj3207][花神的嘲讽计划Ⅰ] (字符串哈希+主席树)
Description 背景 花神是神,一大癖好就是嘲讽大J,举例如下: “哎你傻不傻的![hqz:大笨J]” “这道题又被J屎过了!!” “J这程序怎么跑这么快!J要逆袭了!” …… 描述 这一天D ...
- Linux ——————用Secure传文件时直接拖了文件用的是AssIC导致linux那边直乱码
如下: 解决办法: 直接删除.
- [开源].NET数据库访问框架Chloe.ORM
扯淡 13年毕业之际,进入第一家公司实习,接触了 EntityFramework,当时就觉得这东西太牛了,访问数据库都可以做得这么轻松.优雅!毕竟那时还年轻,没见过世面.工作之前为了拿个实习机会混个工 ...
- [LeetCode] N-Queens N皇后问题
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...
- 《MySQL 必知必会》读书总结
这是 <MySQL 必知必会> 的读书总结.也是自己整理的常用操作的参考手册. 使用 MySQL 连接到 MySQL shell>mysql -u root -p Enter pas ...
- js或css文件后面的参数是什么意思?
经常看到不少导航网站测样式或js文件后面加了一些参数,主要是一你为一些并不经常更新的页面重新加载新修改的文件. 经常遇到页面里加载的js与css文件带有参数,比如: <script type=& ...
- 自建Ceph存储与 AWS、阿里云、腾讯云的成本对比
本文单从存储成本角度对比了自建Ceph存储和业界公有云存储的硬件成本,不包括IDC带宽成本. 统计Ceph集群的用到的主要设备为: OSD.MON.RGW服务器 .TOR交换机. 机架. 下表解释: ...
- mvn-打jar运行包(含环境变量配置)
前沿条件 maven下载:http://maven.apache.org/download.cgi 配置环境变量 MAVEN_HOME= D:\Softwares\apache-maven-3.2.2 ...
- sql 代码笔记
1. if() 函数 推荐一个学习MySQL的网站 Study MySql