查看网关
netstat -rn
or route -en
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 9.134.xxx.1 0.0.0.0 UG 0 0 0 eth1
9.134.xxx.0 0.0.0.0 255.255.252.0 U 0 0 0 eth1
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
查看指定网卡IP
ifconfig eth1 |grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"
查看dns配置
cat /etc/resolv.conf
vim内查找目标
vim file
后,键入/
进入查找模式
/
后接需要查找的目标
- 支持大小写敏感(默认就是大小写敏感)
在查找模式中,加入\c表示大小写不敏感查找,\C表示大小写敏感查找
例如:
/foo\c 大小写不敏感
- 支持正则表达式
例如:
/^foo$\c
- 对于多个结果,键入
n
跳转到下一个,键入N
跳转到下一个
根据文件名查找当前文件夹及其子文件夹的所有文件
find . -type f -name "regular_expression"
从文件中查找匹配pattern的行
grep -e “regular_expression" target_file
Eg.
grep -e "message.*已经分配给ID为" ./do_reservation.log
"message" : "IP[10.0.128.4]已经分配给ID为[574917731]的服务器",
"message" : "IP[10.0.130.20]已经分配给ID为[574918748]的服务器",
# 按:分割并且输出第2部分
grep -e "message.*已经分配给ID为" ./do_reservation.log | cut -d ":" -f 2
"IP[10.0.128.4]已经分配给ID为[574917731]的服务器",
"IP[10.0.130.20]已经分配给ID为[574918748]的服务器",
# 使用 -o --only-matching Prints only the matching part of the lines. 仅输出IP地址
grep -e "message.*已经分配给ID为" ./do_reservation.log | cut -d ":" -f 2 | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
or
grep -e "message.*已经分配给ID为" ./do_reservation.log | cut -d ":" -f 2 | grep -E -o '([0-9]{1,3}[\.]){3}[0-9]{1,3}'
10.0.128.4
10.0.130.20
目录跳转 pushd popd
命令行的当前目录等于目录栈栈顶目录
[user@server /usr/ports] $ pushd /etc
/etc /usr/ports ->pushd后当前目录栈的情况
[user@server /etc] $ popd
/usr/ports ->popd后当前目录栈的情况
[user@server /usr/ports] $
追踪dns查询过程 dig
(domain information groper)
dns的查询过程:DNS客户端和本地名称服务器是递归查询,而本地名称服务器和其他名称服务器之间是迭代查询。Most DNS administrators use dig
command to troubleshoot DNS problems
common command: dig [Options] [TYPE] [Domain_Name]
dig targetdomain
[root@VM-165-116-centos workspace]# dig stackoverflow.com
; <<>> DiG 9.10.6 <<>> stackoverflow.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17243
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION: # -> 显示查询内容,查询stackoverflow.com的A记录
;stackoverflow.com. IN A
;; ANSWER SECTION: # -> 显示dns的应答结果。stackoverflow.com有4个A记录,且time-to-live都是299秒(这个时间内无需重新查询)
stackoverflow.com. 299 IN A 151.101.65.69
stackoverflow.com. 299 IN A 151.101.193.69
stackoverflow.com. 299 IN A 151.101.129.69
stackoverflow.com. 299 IN A 151.101.1.69
;; Query time: 655 msec
;; SERVER: 10.123.119.98#53(10.123.119.98) # -> 本机的dns server是10.123.119.98,dns服务端口为53
;; WHEN: Thu Jan 27 17:36:48 CST 2022
;; MSG SIZE rcvd: 115 # -> 响应字节数115
dig +trace targetdomain
参考https://www.2daygeek.com/dig-command-check-find-dns-records-lookup-linux/
清除dns缓存
What is DNS cache and what it Does?
The DNS cache is a temporary database maintained by the computer’s operating system.
It stores information about previous DNS lookups (like information on recently visited websites and other web domains).
This will quickly resolve DNS queries when you visit the cached website by getting details from the local DNS database instead of the actual DNS server.
How to Clear/Flush the DNS Cache on Linux
By default, DNS caching is not installed or enabled at the OS level, but if you have installed any of the caching services listed below, use the appropriate commands to flush them.
Below is a list of the major DNS cache services used in the Linux operating system.
systemd Resolved Service
nscd DNS Cache
dnsmasq DNS Cache
BIND server DNS Cache
systemd Resolved Service
Most modern Linux operating systems use systemd as the default init proccess(当前大部分linux os 使用systemd作为默认的init程序), so use the command below to flush the DNS cache.
$ sudo systemctl is-active systemd-resolve.service # check if the DNS cache service is active on your system.
$ sudo systemd-resolve --flush-caches
nscd DNS Cache
nscd stands for name service cache daemon, nscd is a daemon that provides a cache for the most common name service requests. The default configuration file located at /etc/nscd.conf. 里面配置了enable-cache的类型、time-to-live、max-db-size等参数,决定了哪些信息需要被cached、保持时长、cached数据库大小等
$ sudo systemctl restart nscd # 重启以清理缓存
dnsmasq DNS Cache
Dnsmasq is a lightweight, small footprint, easy to configure, DNS forwarder and DHCP server. It is designed to provide DNS and optionally, DHCP, to a small network & suitable for resource constrained routers and firewalls. It can serve the names of local machines which are not in the global DNS. It is designed for personal computer use and small size networks, not for big networks. dnsmasq为私有dns服务
$ sudo systemctl restart dnsmasq # 重启以清理缓存
BIND Server DNS Cache
BIND stands for “Berkeley Internet Name Domain”. The most widely used Name Server Software, BIND is open source software that implements the Domain Name System (DNS) protocols for the Internet. BIND is by far the most widely used DNS software on the Internet, providing a robust and stable platform. 通过起named service来提供dns服务
$ sudo systemctl restart named # 使用重启服务的方式,flush the BIND server DNS cache on Systemd-based Linux systems.
or
$ sudo rndc flushname 2daygeek.com # rndc, named的服务管理工具,指定删除某个域名的dns缓存
很多dns服务都通过重启来实现清理缓存的目的
修改环境变量
- 永久生效:
-
系统环境变量
vim /etc/profile
source /etc/profile
-
用户shell环境变量
Linux系统中有很多种类的shell,不管是bash,sh,dash,都会有一个~/.bashrc的隐藏文件,该文件存在于用户的家目录,是每一个用户运行shell时执行的文件,当shell被打开时,该文件被读取。这个文件主要保存个人用户的一些个性化的设置
vim ~/.bashrc
source ~/.bashrc
-
cat ~/.bashrc
# .bashrc
# User specific aliases and functions
# for TencentOS, remove these aliases
#alias rm='rm -i'
#alias cp='cp -i'
#alias mv='mv -i'
# Source global definitions ->source用户的~/.bashrc前,会先source一下全局bashrc
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export PATH="$PATH:$HOME/.ft:$GOPATH/bin"
- 当前shell临时生效的变量
eg.export PATH=$PATH:/opt/au1200_rm/build_tools/bin
内核
一个os发行版可以支持多个kennel
安装内核 yum install 内核
,在grab.conf中配置使用的内核
网友评论