Linux学习笔记之超详细基础linux命令

by:授客 QQ1033553122

---------------------------------接Part 14------------------------------

例子:将网卡的ip地址设置为192.168.0.3

[root@localhost laiyu]# ifconfig eth0 192.168.1.3

[root@localhost laiyu]# ifconfig

eth0      Link encap:Ethernet  HWaddr 20:6A:8A:7E:65:A2

inet addr:192.168.1.3  Bcast:192.168.1.255  Mask:255.255.255.0

...

如果只指定网卡的ip地址,那么网卡将使用默认的子网掩码。

例:停用网卡eth0

[root@localhost laiyu]# ifconfig eth0 down

[root@localhost laiyu]# ifconfig

lo        Link encap:Local Loopback

inet addr:127.0.0.1  Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING  MTU:16436  Metric:1

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

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

collisions:0 txqueuelen:0

RX bytes:1408 (1.3 KiB)  TX bytes:1408 (1.3 KiB)

ifup和ifdown命令

方法:

ifup 网络接口

ifdown 网络接口

功能:启用或停用网络接口

例:启用网卡eth0

[root@localhost laiyu]# ifup eth0

正在决定 eth0 的 IP 信息...完成。

等价命令

方法:

ifconfig 网络接口名 down

功能:停用网络接口

ifconfig 网络接口 up

功能:启用网络接口

ping命令

方法:ping [-c 次数] IP地址|主机名

功能:测试网络的连通性

例子:测试与ip地址为192.168.1.4的主机的连通情况

[root@localhost laiyu]# ping 192.168.1.4

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

64 bytes from 192.168.1.4: icmp_seq=1 ttl=64 time=0.071 ms

64 bytes from 192.168.1.4: icmp_seq=2 ttl=64 time=0.060 ms

64 bytes from 192.168.1.4: icmp_seq=3 ttl=64 time=0.064 ms

...

例子:测试与www.baidu.com计算机的连通状况。

[root@localhost laiyu]# ping -c 2 www.baidu.com

PING www.a.shifen.com (220.181.111.83) 56(84) bytes of data.

64 bytes from 220.181.111.83: icmp_seq=1 ttl=54 time=66.7 ms

64 bytes from 220.181.111.83: icmp_seq=2 ttl=54 time=68.3 ms

--- www.a.shifen.com ping statistics ---

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

rtt min/avg/max/mdev = 66.771/67.538/68.305/0.767 ms

如果不指定发送数据包的次数,那么ping命令就会一直下去。直到用户按【Ctrl+C】组合键。

[root@localhost laiyu]# ping www.baidu.com

PING www.a.shifen.com (220.181.111.188) 56(84) bytes of data.

64 bytes from 220.181.111.188: icmp_seq=1 ttl=54 time=74.2 ms

64 bytes from 220.181.111.188: icmp_seq=2 ttl=54 time=67.7 ms

64 bytes from 220.181.111.188: icmp_seq=3 ttl=54 time=135 ms

当参数是主机名时,ping命令可从DNS服务器获取其ip地址。这一命令也可以测试DNS服务器是否正常运行。

在实际应用中“ping 127.0.0.1”命令测试tcp协议栈是否正常,不正常则需要重新安装tcp/ip协议

ping “本机ip地址” 命令格式可测试本机的ip地址是否正确

route命令

功能:查看内核路由表的配置情况,操纵路由表,主要用于设置通过某个接口往指定主机或网络的静态路由,默认路由,本地路由

方法:

route  [-CFvnee]

route  [-v] add [-net|-host] target [netmask Nm] [gw Gw] [[dev] If]

route  [-v] del [-net|-host] target [gw Gw] [netmask Nm] [[dev] If]

route  [-V] [--version] [-h] [--help]

主要选项:

-F     显示内核FIB转发信息表(缺省)

-C     显示内核路由缓存

-n     以数字形式的地址显示主机,而不显示特征主机名

del    删除一条路由

add    添加一条路由

target 目标网络或主机,形式可以是点分ip地址,或者网络地址

-net   目标是一个网络

-host  目标是一台主机

netmask NM   当添加一个网络路由时,要用到子网掩码

gw
GW 
route数据包通过一个网关,注意:指定网关必须可打.这意味着你必须先建立一条通过网关的静态路由,如果指定你本地接口的某个地址,它将决定数据包应该往哪个接口进行路由

dev
if

强制让路由同指定设备关联,否则内核会根据已经存在的路由和设备进行自主选择。

if 
同dev
if

例子:添加网关,其ip地址为192.168.0.100

[laiyu@localhost ~]$ route
add default gw 192.168.0.100

SIOCADDRT:
Operation not permitted

[laiyu@localhost ~]$
su

Password:

[root@localhost laiyu]#
route add default gw 192.168.1.255

SIOCADDRT:

没有那个进程

注:网上说应该注意添加路由的网关,能否由现在的ip routing
table路由出去,若不能,很可能是这个原因,也就是说网关不存在

例子:显示路由表

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway    
    Genmask        
Flags Metric Ref   
Use Iface

10.6.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth2.3

10.7.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth0

例子:显示路由表,不显示主机名

HDFW:~#
route -n

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.6.0.0       
0.0.0.0        
255.255.0.0    
U    
0     
0       
0 eth2.3

10.7.0.0       
0.0.0.0        
255.255.0.0    
U    
0     
0       
0 eth3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
0.0.0.0        
255.255.0.0    
U    
0     
0       
0 eth0

例子:删除往目标网络10.7.x.x

的路由

route del
-net 10.7.0.0 netmask 255.255.0.0

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.6.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth2.3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth0

例子:添加通往目的网络的默认网关,也就是我们常说的添加默认路由

HDFW:~#
route add default gw 10.5.0.1

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.6.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth2.3

10.4.0.0       
10.5.0.1       
255.255.0.0   
 UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth0

default        
10.5.0.1       
0.0.0.0        
UG   
0     
0       
0 eth0

例子:添加通过eth0往目的主机的10.4.8.243

路由

HDFW:~#
route add 10.4.8.243 eth0  #应该也是可以这样route
add 10.4.8.243 dev eth0

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.4.8.243     
*              
255.255.255.255 UH   
0     
0       
0 eth0

10.6.0.0       
*       
       255.255.0.0    
U    
0     
0       
0 eth2.3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth0

default        
10.5.0.1       
0.0.0.0        
UG   
0     
0       
0 eth0

说明1:添加主机是不需要指定子网掩码的,反过来说如添加了子网掩码,则表示网络了

HDFW:~#
route add host 10.4.8.243 netmask 255.255.0.0 eth0

host:
Unknown host

说明2:

因特网所有的分组转发都是基于目的主机所在的网络,但大多数情况下,都允许有这样的特例,即对特定的目的主机指明一个路由.这类路由就叫特定主机路由。

采用特定主机路由可让网管人员更方便地控制网络和测试网络,同时也可以在需要考虑某种安全问题时采用这种特定主机路由。

在对网络的链接或路由表进行排错时,指明某一主机的特定路由是很有用的。子网掩码固定为全32位

添加一条经过网关10.5.0.1通往目的网络10.4.0.1的路由

HDFW:~#
route add -net 10.4.0.0 netmask 255.255.0.0 gw 10.5.0.1

SIOCADDRT:
File exists

说明:如果不存在则可以添加

HDFW:~#
route add -net 10.6.0.0 netmask 255.255.0.0 gw 10.5.0.1

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.6.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.6.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth2.3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth0

例子:删除一条经接口eth0,通过网关10.5.0.1,往目的网络10.4.0.1的路由

HDFW:~#
route del -net 10.6.0.0 netmask 255.255.0.0 gw 10.5.0.1 dev
eth0

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.6.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth2.3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth0

例子:删除往目的网络的路由,形式host/network

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.7.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0    
 0       
0 eth0

HDFW:~#
route del -net 10.7.0.0/16

例子:删除往目的主机10.4.8.243的路由

HDFW:~#
route add 10.4.8.243 gw 10.5.0.1 eth0

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.4.8.243     
10.5.0.1       
255.255.255.255 UGH  
0     
0       
0 eth0

10.6.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth2.3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth0

HDFW:~#
route del 10.4.8.243 dev eth0

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.6.0.0       
*              
255.255.0.0    
U    
0     

      0
eth2.3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth0

-----------------------------------------------------------------------

例子:常见问题:netmask doesn't match route
address

HDFW:~#
route add -net 10.7.8.0 netmask 255.255.0.0 dev eth3

route:
netmask doesn't match route address

Usuage:......

......

解决方案:

HDFW:~#
route add -net 10.7.0.0 netmask 255.255.0.0 dev eth3

HDFW:~#
route

Kernel IP
routing table

Destination    
Gateway        
Genmask        
Flags Metric Ref   
Use Iface

10.6.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth2.3

10.7.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth3

10.4.0.0       
10.5.0.1       
255.255.0.0    
UG   
0     
0       
0 eth0

10.5.0.0       
*              
255.255.0.0    
U    
0     
0       
0 eth0

管理服务

管理服务的Shell命令

serivce命令

方法:service
服务名 start|stop|restart

功能:启动、终止或重启指定的服务。

例子:启动Samba服务

[root@localhost ~]# service
smb start

例子:停止Apache服务器

[root@localhost ~]# service
httpd stop

例子:重新启动Vsftp服务。

[root@localhost ~]# service
vsftpd restart

例子:重启网络服务

# service
network restart

例子:重启防火墙服务

# service
iptables restart

Linux 学习笔记之超详细基础linux命令(the end)的更多相关文章

  1. Linux 学习笔记之超详细基础linux命令 Part 14

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 13---------------- ...

  2. Linux 学习笔记之超详细基础linux命令 Part 13

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 12---------------- ...

  3. Linux 学习笔记之超详细基础linux命令 Part 12

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 11---------------- ...

  4. Linux 学习笔记之超详细基础linux命令 Part 11

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 10---------------- ...

  5. Linux 学习笔记之超详细基础linux命令 Part 10

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 9----------------- ...

  6. Linux 学习笔记之超详细基础linux命令 Part 9

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 8----------------- ...

  7. Linux 学习笔记之超详细基础linux命令 Part 8

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 7----------------- ...

  8. Linux 学习笔记之超详细基础linux命令 Part 7

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 6----------------- ...

  9. Linux 学习笔记之超详细基础linux命令 Part 6

    Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 5----------------- ...

随机推荐

  1. requsets模块的学习

    requests模块的学习 使用之前 pip install requests 发起get,post,请求获取响应 response = requests.get(url,headers) # 发起g ...

  2. vue 自学笔记(5) 列表渲染

    列表渲染 一:v-for 指令 当我们涉及到列表渲染数据的时候,不可能做一个重复的工作去不停的一个一个的渲染每一项列表.并且列表数据的表现,比如从后端请求过来的数据,不可能是一个一个的单独的 JSON ...

  3. 678 "流浪地球"为什么是个好地方?(系统越复杂拥有好运气的机会也就越大)

    运气,其实就是一个复杂系统孕育出的,超出已知经验的解决方案.它不是没有产生机制.只不过,这个机制太复杂,涉及的因素太多.我们没法复制.所以,我们只能笼统的,把这套机制称为运气,或者命数. 举个例子,假 ...

  4. H5拖动火狐自动打开新标签

    写在前面的话:<H5拖动火狐自动打开新标签>原因是为什么百度很多了我就不细说,本文章只说我自己的解决方法... 自定义数据里写个链接,如果火狐自动打开就跳到这个链接 这个页面就写一句话:关 ...

  5. linux中一些简便的命令之tac/comm

    tac tac是cat的反写,即反序显示文件内容 如文件a.txt内容如下: 1 2 3 4 5 则tac a.txt打印如下: 54321 我们可以使用awk来实现tac的功能: awk '{arr ...

  6. 使用.NET Core与Google Optimization Tools实现加工车间任务规划

    前一篇文章<使用.NET Core与Google Optimization Tools实现员工排班计划Scheduling>算是一种针对内容的规划,而针对时间顺序任务规划,加工车间的工活儿 ...

  7. ProxySQL 配置详解及读写分离(+GTID)等功能说明 (完整篇)

    ProxySQL是灵活强大的MySQL代理层, 是一个能实实在在用在生产环境的MySQL中间件,可以实现读写分离,支持 Query 路由功能,支持动态指定某个 SQL 进行 cache,支持动态加载配 ...

  8. 设计node.js搭建多人博客的思路(不讲数据库)

    1.1.4:搭建多人博客 1.功能分析 搭建一个简单的多人注册,登录,发表文章及登出功能的博客 2.设计目标 未登录:主页左侧导航显示home.login.register,右侧显示已发表文章,发表日 ...

  9. 子shell以及什么时候进入子shell

    bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 子shell的概念贯穿整个shell,写shell脚本时更是不 ...

  10. 小白Python路上第一个难点,也是一个比较重要的点(闭包,迭代器,生成器)

    一.闭包 闭包就是在内层函数中引用外层函数的变量 作用:1.保护变量不受侵害          2.让一个变量永驻内存 二.迭代器 Iterator:迭代器,包含_iter_()和_next_()函数 ...