Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUIDE] How to connect to printer with ethernet cable directly connected to PC #256

Open
R1D3R175 opened this issue Feb 8, 2025 · 0 comments

Comments

@R1D3R175
Copy link

R1D3R175 commented Feb 8, 2025

The wiki says that Ethernet connection doesn't work if plugged directly to the PC, which is true if you consider only an out-of-the-box approach.

I propose the following "guide" that make your PC behave like a DHCP server and also allow the printer to connect to the Internet with NAT.

Prerequisites

  • root level permissions (i.e. sudo)
  • dnsmasq installed
  • iptables installed

Configuration

Assigning a static IP address to ethernet interface

FIrst of all decide an IP subnet, in my case I choose 10.0.0.0/24.

Now assign a static IP to your ethernet interface, I did it via nmtui since it's the easiest (doing it via ip command will assign but then it would get almost instantly removed, probably by NetworkManager itself).

To assign a static IP to your interface do the following (assuming that you have nmtui opened)

  1. Edit a connection
  2. Ethernet > Wired connection 1 (i.e. the ethernet interface which will be used to connect to the printer)
  3. IPv4 CONFIGURATION -> Manual
  4. IPv4 CONFIGURATION -> Addresses -> 10.0.0.1/24
  5. Check "Never use this network for default route"
  6. Check "Ignore automatically obtained routes"
  7. Check "Ignore automatically obtained DNS parameters"
  8. Uncheck "Require IPv4 addressing for this connection"
  9. Check "Automatically connect"
  10. Check "Available to all users"
  11. Press OK, then you can exit from nmtui.

Configuring dnsmasq

Now we have to configure dnsmasq so open the configuration file at /etc/dnsmasq.conf and write the following

interface=enp4s0

dhcp-range=10.0.0.10,10.0.0.20,12h

listen-address=10.0.0.1
bind-interfaces

Remember to modify interface, dhcp-range and listen-address according to your IPs.

Configure IP forwarding & NAT

Now we have configuare IP forwarding and NAT

To enable IP forwarding, switch to root with sudo su - and then execute the following command

echo 1 > /proc/sys/net/ipv4/ip_forward

You can check if it has been enabled successfully with

sysctl net.ipv4.ip_forward

Then modify the iptables with the following command (you don't need to be root for this, sudo works fine here)

iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

Where wlan0 is the interface that you use to access the internet from your PC

Connecting to the printer

Now connect the printer to the PC with the ethernet cable and check with ip -c a when your ethernet interface gets the static IP, when it gets it you can start dnsmasq with sudo dnsmasq (or, if you prefer, you may also start it as a systemd service`).

At this point just wait a little bit and your printer will get an IP address, to know which address just check dnsmasq logs using either systemctl status dnsmasq or journalctl -xe | grep dnsmasq; you should see something like this.

dnsmasq-dhcp[172127]: DHCPDISCOVER(enp4s0) 42:c8:64:72:7f:7d
dnsmasq-dhcp[172127]: DHCPOFFER(enp4s0) 10.0.0.11 42:c8:64:72:7f:7d
dnsmasq-dhcp[172127]: DHCPREQUEST(enp4s0) 10.0.0.11 42:c8:64:72:7f:7d
dnsmasq-dhcp[172127]: DHCPACK(enp4s0) 10.0.0.11 42:c8:64:72:7f:7d znp-k1

You can now connect to the printer with SSH using ssh [email protected] and check if it has connection to the internet with a simple ping

$ ssh [email protected]
[email protected]'s password:
 ______   _ ____       _  ___
|__  / \ | |  _ \     | |/ / |
  / /|  \| | |_) |____| ' /| |
 / /_| |\  |  __/_____| . \| |
/____|_| \_|_|        |_|\_\_|

Welcome to Armbian-unofficial 24.2.0-trunk Bookworm with Linux 6.1.67-current-rockchip64

No end-user support: built from trunk

System load:   2%               Up time:       26 min
Memory usage:  19% of 976M      Zram usage:    10% of 488M      IP:            10.0.0.11
CPU temp:      58°C             Usage of /:    67% of 6.7G
RX today:      291.2 MiB

[ Kernel and firmware upgrades disabled: armbian-config ]
Last check: 2025-02-08 18:18

[ General system configuration (beta): armbian-config ]

Last login: Thu Dec 14 15:17:47 2023 from 10.0.0.1

mks@znp-k1:~$ ping google.com
PING google.com (142.251.209.14): 56 data bytes
64 bytes from 142.251.209.14: icmp_seq=0 ttl=119 time=45.579 ms
64 bytes from 142.251.209.14: icmp_seq=1 ttl=119 time=26.641 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant