温馨提示×

CentOS Dolphin网络配置详解

小樊
48
2025-10-07 06:16:36
栏目: 智能运维

Note: “CentOS Dolphin” typically refers to CentOS 8/Stream 8 (or later) with the KDE Plasma Desktop Environment (where Dolphin is the default file manager). Network configuration in this context involves system-wide network settings (managed by NetworkManager) rather than Dolphin-specific configurations. Below is a detailed guide to system network configuration, which Dolphin relies on for network access.

1. Prerequisites

  • Ensure you have root privileges (or use sudo for commands).
  • Confirm the network interface name (e.g., ens33, eth0) using:
    ip addr show
    
    Look for interfaces with “UP” status (e.g., ens33).

2. Method 1: Using Command-Line Tools

2.1 View Current Network Configuration

  • Check interface details (IP, MAC, state):
    ip addr show <interface>  # e.g., ip addr show ens33
    
  • Verify routing (gateway):
    ip route show
    
  • Test connectivity:
    ping 8.8.8.8  # Replace with a valid IP/hostname
    

2.2 Configure Static IP Address (Persistent)

  • Edit the interface configuration file (replace ens33 with your interface):
    sudo vi /etc/sysconfig/network-scripts/ifcfg-ens33
    
  • Modify/Add these lines (adjust values to your network):
    BOOTPROTO=static       # Disable DHCP
    ONBOOT=yes             # Enable at boot
    IPADDR=192.168.1.100   # Static IP
    NETMASK=255.255.255.0  # Subnet mask (or use PREFIX=24)
    GATEWAY=192.168.1.1    # Default gateway
    DNS1=8.8.8.8           # Primary DNS
    DNS2=8.8.4.4           # Secondary DNS
    
  • Save and exit (:wq in vi).

2.3 Restart Network Services

  • Apply changes using NetworkManager:
    sudo systemctl restart NetworkManager
    
  • Verify the new configuration:
    ip addr show ens33
    ping www.google.com   # Test external connectivity
    

2.4 Configure DHCP (Automatic IP)

  • Edit the same file (ifcfg-ens33):
    BOOTPROTO=dhcp         # Enable DHCP
    ONBOOT=yes
    
  • Restart NetworkManager:
    sudo systemctl restart NetworkManager
    

3. Method 2: Using Graphical Tools (nmtui)

For users preferring a GUI, nmtui (NetworkManager Text User Interface) is available:

  1. Open the terminal and run:
    sudo nmtui
    
  2. Navigate to “Edit a connection” (use arrow keys) and select your interface (e.g., ens33).
  3. Choose “Edit” and configure:
    • IPv4 Configuration: Select “Manual”.
    • Enter IP, Netmask (or Prefix), Gateway, and DNS servers.
  4. Click “OK” to save, then “Back” to exit.
  5. Restart the network service:
    sudo systemctl restart NetworkManager
    

4. Method 3: Using nmcli (Command-Line Tool)

nmcli is a powerful CLI for NetworkManager:

  1. List existing connections:
    nmcli connection show
    
  2. Edit the desired connection (replace ens33 with your connection name):
    sudo nmcli connection edit ens33
    
  3. Configure static IP:
    set ipv4.addresses 192.168.1.100/24
    set ipv4.gateway 192.168.1.1
    set ipv4.dns "8.8.8.8,8.8.4.4"
    set ipv4.method manual
    
  4. Save and activate:
    save
    activate
    
  5. Verify:
    nmcli connection show ens33 | grep IPV4
    

5. Verify Network Connectivity

After any configuration change, use these commands:

  • Check interface IP:
    ip addr show <interface>
    
  • Test local network:
    ping 192.168.1.1  # Replace with your gateway
    
  • Test internet access:
    ping www.google.com
    
  • Check DNS resolution:
    nslookup google.com
    

6. Troubleshooting Common Issues

  • Interface not showing: Ensure the interface is enabled (ip link set <interface> up).
  • No IP assigned: Verify DHCP server availability or correct static IP settings.
  • Connection drops: Check cable integrity, router settings, or firewall rules (sudo firewall-cmd --list-all).
  • DNS resolution fails: Edit /etc/resolv.conf (add nameserver 8.8.8.8) or use nmcli to update DNS.

By following these steps, you can configure system-wide network settings for CentOS 8/Stream 8 (with KDE Plasma). Dolphin will automatically use these settings for network access.

0