Linux常用技巧
一、基础操作
1、开关机
INIT命令
#关机
init 0
#重启
init 6
SHUTDOWN命令
#立刻关机
shutdown -h now
#10分钟后关机
shutdown -h 10
#重启
shutdown -r now
2、NIC
1)IP
静态IP地址设置
ifconfig #查看当前所有网卡
ifconfig eth0 192.168.1.1/24 #针对eth0网卡设置临时静态IP地址
Linux下的网卡配置需要用到管理员权限,一般在非管理员但属于sudo用户组中的用户可以在ifconfig命令前输入sudo,否则会被系统因为权限不足拒绝执行。
网卡文件设置IP
KALI中网卡文件需要设置网关网络所在的网卡,否则没有效果。根据网络情况配置网卡是否为静态设置还是动态分配。如果是静态设置,请参考#The Eth0 network interface(static)下五行的配置;如果是动态分配,请参考#The Eth0 network interface(dhcp)下两行的配置。
vim /etc/network/interfaces
# This file describes the network interface available on your system.
# and how to activate them. For more information, see interface(5)
source /etc/ntework/interfaces.d/*
#The loopback network interface
auto lo
iface lo inet loopback
#The Eth0 network interface(static)
auto eth0
iface eth0 inet static #网卡选择静态设置
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.254
#The Eth0 network interface(dhcp)
auto eth0
iface eth0 inet dhcp #网卡选择DHCP自动配置
systemctl restart networking.service #修改完网卡文件后重启网卡服务
2)Mac
ifconfig eth0 hw ether 00:11:22:33:44:55 #临时修改网卡MAC
systemctl restart networking.service #重启网卡服务
3)Route
路由用于数据包的转发。通常终端主机只需要设置网关路由即可。
默认路由
route #查看当前路由表
route add -net default gw 192.168.1.254 dev eth0 #新增临时网关路由
route del -net default gw 192.168.1.254 #删除临时网关路由
明细路由
route add -net 192.168.1.0/24 gw 192.168.1.4 metric 1 dev eth0 #新增临时明细浮动路由,Metric用于设置相同静态路由的优先级
route del -net 192.168.1.0/24 gw 192.168.1.4 metric 1 dev eth0 #删除临时明细浮动路由
4)DNS
临时修改DNS
临时修改DNS通常只需要修改/etc/resolv.conf文件即可,在文件末尾处添加如下配置并重启网卡服务,但是此方式在Linux终端重启后失效。
vim /etc/resolv.conf
nameserver 114.114.114.114
systemctl restart networking.service #重启网卡服务
永久修改DNS
永久修改DNS通常只需要修改/etc/dhcp/dhclient.conf文件即可,在文件末尾处添加如下配置并重启网卡服务。
vim /etc/dhcp/dhclient.conf
supersede domain-name-servers 114.114.114.114,8.8.8.8;
3、ARP
arp -n #查看ARP缓存表项
arp -d 192.168.1.1 #删除某一条ARP缓存表项
arp -s 192.168.1.1 fe:ee:aa:ce:f0:a1 #新增某一条ARP缓存表项
4、更新源
通常我们使用的Linux发行版本的软件更新仓库的服务器位于全球各地,同时因为国内的国情,当使用软件包管理器更新或下载软件时会出现无法访问的情况,因此需要修改软件更新仓库的地址。
KALI
vim /etc/apt/source.list
deb https://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main non-free contrib
Ubuntu
vim /etc/apt/source.list
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
二、安全功能
1、服务器禁Ping
服务器禁Ping可以通过修改内核参数或者启用防火墙实现。
1)内核参数禁Ping
临时禁Ping# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
永久禁Ping# vim /etc/sysctl.conf
net.ipv4.icmp_echo_ignore_all=1
2)防火墙禁Ping
防火墙禁Ping#
评论