Linux · 11月 8, 2020

CentOS常用设置

联网设置

查看可用的网卡(不用ifconfig)

nmcli con

固定IP

  1. 用文本编辑器打开接口配置文件

# vim /etc/sysconfig/network-scripts/

  1. 修改以下内容
BOOTPROTO=static
ONBOOT=yes
IPADDR=<静态IP>
GATEWAY=<默认网关>
NETMASK=<子网掩码>
DNS1=<DNS>
  1. 重启网络服务
service network restart

修改hostname

hostnamectl --static set-hostname <主机名>

👆其实主机名有static(静态,一般用于永久修改)、transient(系统运行时临时分配)、pretty(用于当前终端用户)三种

系统代理

  • 在CLI界面输入
export ALL_PROXY="https://username:password@proxy_ip:port"

👆如果想对所有用户开机生效,把这行写进/etc/profile里,并用source /etc/profile使之立即生效

Wget代理

/etc/wgetrc里,取消掉下文注释并加入需要的内容

http_proxy=http://<user>:<pwd>@<host>:<port>

修改ulimit(重启不失效)

/etc/security/limits.conf中添加以下内容:

* soft nofile 65535
* hard nofile 65535

YUM包管理

引入epel源(建议都这么做一下)

yum -y install epel-release

查询维护

查看哪个进程占用了某个端口

# 最小安装的CentOS需要事先安装lsof
yum install lsof
lsof -i:80