先明确组件与前提
Debian 主机网络配置
auto eth0
iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.168.4.4
sudo systemctl restart networking
ip addr show eth0
sudo apt-get update
sudo apt-get install -y network-manager
sudo systemctl start NetworkManager
sudo systemctl enable NetworkManager
nmcli con mod eth0 ipv4.method manual ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns "8.8.8.8 8.8.4.4"
nmcli con up eth0
sudo nano /etc/netplan/01-netcfg.yaml
# 示例
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
sudo netplan apply
以上三种方式任选其一,确保主机具备正确的 IP/网关/DNS 后,再让上层应用发起网络请求。
应用层网络设置(供使用 cxImage 的程序参考)
#include <curl/curl.h>
CURL *curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/image.jpg");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "MyApp/1.0");
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip, deflate");
// 生产环境请设置 CURLOPT_SSL_VERIFYPEER 与 CURLOPT_CAINFO
CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
若你指的是“CXImage 服务/守护进程”的网络参数
[network]
ip = 0.0.0.0
port = 8080
[limits]
max_connections = 100
timeout = 30
sudo systemctl start cximage
sudo systemctl enable cximage
sudo systemctl status cximage
sudo systemctl reload cximage
sudo ufw allow 8080/tcp
sudo ufw reload
上述键名与命令为常见做法,具体请参照你所使用的服务版本文档。