linux常用-设置代理及IP

一、linux设置代理

cat /etc/profile 配置文件

#系统代理设置默认使用的代理
http_proxy=http://user:lwp123%[email protected]:7777/ 
https_proxy=$http_proxy
export http_proxy https_proxy

# java环境配置
export JAVA_HOME=/usr/local/java/jdk1.8.0_171
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
 # export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

二、设置IP地址

网卡信息存放在 /etc/sysconfig/network-scripts/ 路径下, 查看/etc/sysconfig/network-scripts/ifcfg开头的文件

打开网卡文件编辑

cd  /etc/sysconfig/network-scripts/ 
vi /etc/sysconfig/network-scripts/ifcfg-eth0

编辑本地网卡的配置文件
主要查看下面这几项是否和下面给出的一致即可。

ONBOOT=yes
# BOOTPROTO=none  # 值为static或dhcp、none,配置IPADDR="192.168.0.162"时为静态地址
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
IPADDR=192.168.1.100
# DNS1=8.8.8.8  # 144.144.144.144
# DNS2=8.8.8.8

静态地址配置实例

[root@localhost network-scripts]# cat ifcfg-ens33
TYPE="Ethernet"
GATEWAY="192.168.0.1"
IPADDR="192.168.0.162"
NAME="ens33"  #网卡名
ONBOOT="yes"

修改后重启网卡
重启网卡命令一

service network restart

重启网命令二

systemctl restart network

如下和之前简化的效果相同

[root@localhost network-scripts]# cat ifcfg-ens33
TYPE="Ethernet"
#BOOTPROTO="static"  # 值为static或dhcp、none,配置IPADDR="192.168.0.162"时为静态地址
GATEWAY="192.168.0.1"
IPADDR="192.168.0.162"
#NETMASK="255.255.255.0"  #  默认255.255.255.0
NAME="ens33"
ONBOOT="yes"

网卡信息

[root@localhost network-scripts]# ifconfig
ens33: flags=4163  mtu 1500
        inet 192.168.0.162  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe1d:7cd4  prefixlen 64  scopeid 0x20
        ether 00:0c:29:1d:7c:d4  txqueuelen 1000  (Ethernet)
        RX packets 1462  bytes 652455 (637.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 248  bytes 33860 (33.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

DNS设置

centos

cat /etc/resolv.conf 查看
vi /etc/resolv.conf 修改

[root@localhost network-scripts]# cat /etc/resolv.conf
nameserver 8.8.8.8
#nameserver 114.114.114.114

你可能感兴趣的:(linux)