date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,395,122,243,000
I have an NIC card on a Debian machine somewhere. The machine is turned off, but I need to know whether the NIC card is turned on so that I can send a wake-on-lan magic packet later (from another Debian machine) to wake it up. I have the MAC address of the card. Is there any way I can ping the ethernet card by MAC to see whether it is on? I tried creating an ARP entry: arp -s 192.168.2.2 00-0c-0d-ef-02-03 ping 192.168.2.2 That didn't work, since the NIC card does not have this ip address. So the NIC card would receive the ping request but would not reply to it. Is there any way around this? I am using the etherwake package to send a wake-on-lan message.
You might have better luck using the tool arping instead. The tool ping works at the layer 3 level of the OSI model, whereas arping works at layer 2. You still need to know the IP of the system however with this tool. There are 2 versions of it, the standard one included with most Unixes (Alexey Kuznetsov's) is the version that can only deal with IP addresses. The other version (Thomas Habets') supposedly can query using MAC addresses. $ sudo arping 192.168.1.1 -c 1 ARPING 192.168.1.1 from 192.168.1.218 eth0 Unicast reply from 192.168.1.1 [00:90:7F:85:BE:9A] 1.216ms Sent 1 probes (1 broadcast(s)) Received 1 response(s) arping works similarly to ping except instead of sending ICMP packets, it sends ARP packets. Getting a system's IP using just the MAC Here are a couple of methods for doing the reverse lookup of MAC to IP. nmap $ nmap -sP 192.168.1.0/24 Then look in your arp cache for the corresponding machine arp -an. fping $ fping -a -g 192.168.1.0/24 -c 1 Then look in your arp cache, same as above. ping $ ping -b -c1 192.168.1.255 Then look in your arp cache, same as above. nbtscan (windows only hosts) $ nbtscan 192.168.1.0/24 Doing NBT name scan for addresses from 192.168.1.0/24 IP address NetBIOS Name Server User MAC address ------------------------------------------------------------------------------ 192.168.1.0 Sendto failed: Permission denied 192.168.1.4 MACH1 <server> <unknown> 00-0b-12-60-21-dd 192.168.1.5 MACH2 <server> <unknown> 00-1b-a0-3d-e7-be 192.168.1.6 MACH3 <server> <unknown> 00-21-9b-12-b6-a7
Can one ping a NIC by MAC
1,395,122,243,000
I have found some tools that seems to update the OUI MAC address vendor database on my system, like get-oui, airodump-ng-oui-update or update-oui : update-oui(8) OUI update-oui(8) NAME update-oui - download new version of the OUI and IAB lists SYNOPSIS update-oui DESCRIPTION update-oui fetches the current version of the OUI and IAB lists from http://standards.ieee.org/regauth/oui/index.shtml and installs it, if the installed versions is older than 5 days. This utility requires curl, wget or libwww-perl to be installed. OPTIONS -q Be quiet. Do not output messages. -f Force the update, even if the file is newer than 5 days. FILES /usr/share/misc/ Directory holding symbolic links to oui.txt and iab.txt But if I search for IPs on my network: luis@Zarzamoro:~$ sudo netdiscover -i eth1 92 Captured ARP Req/Rep packets, from 12 hosts. Total size: 5520 _____________________________________________________________________________ IP At MAC Address Count Len MAC Vendor ----------------------------------------------------------------------------- 192.168.4.31 bc:f1:f2:12:b4:93 60 3600 Unknown vendor 192.168.4.24 f0:db:e2:de:11:80 02 120 Unknown vendor 192.168.4.242 00:1d:7e:9c:6e:fc 05 300 Cisco-Linksys, LLC 192.168.4.243 00:1c:10:64:63:ac 05 300 Cisco-Linksys, LLC 192.168.4.244 00:1c:10:64:5f:94 05 300 Cisco-Linksys, LLC 192.168.4.1 d8:61:94:e5:0b:1d 05 300 Unknown vendor 192.168.4.246 00:1a:70:2f:ab:4b 04 240 Cisco-Linksys, LLC 192.168.4.10 84:11:9e:2b:1c:d6 01 060 Unknown vendor 192.168.4.11 ec:1f:72:5d:42:d0 02 120 Unknown vendor 192.168.4.245 00:1a:70:2f:aa:63 01 060 Cisco-Linksys, LLC 192.168.4.248 00:1a:70:2f:aa:d1 01 060 Cisco-Linksys, LLC 192.168.4.251 44:d9:e7:0a:0b:98 01 060 Unknown vendor As long as there are some MACs reported as Unknown vendor, I would like to search on any OUI database for its info. What is the proper command-line way to perform this search? Maybe something like: oui-info 44:d9:e7 Note: I know that using the web browser I can google for the MAC's first 3 pairs, but I would like some command-line method, so I could script it or use via remote login (SSH).
I do not think there is an automated tool to do what you ask, but can be done by working directly on files oui.txt. First of all it identifies the file downloaded, for example: root@kalilloX:~# locate oui.txt /var/lib/ieee-data/oui.txt then search for the string you are interested. You must remove : or instead insert a -: root@kalilloX:~# grep -i "44d9e7" /var/lib/ieee-data/oui.txt 44D9E7 (base 16) Ubiquiti Networks, Inc.
Command-line tool to obtain OUI vendor info from MAC address?
1,395,122,243,000
I changed my MAC address with macchanger -A wlp68s0b1 at boot with crontab, Here is what happens when I disconnect and reconnect: While connecting after boot: rahman@debian:~$ macchanger -s wlp68s0b1 Current MAC: 00:22:31:c6:38:45 (SMT&C Co., Ltd.) Permanent MAC: 00:00:00:00:00:00 (FAKE CORPORATION) After disconnecting: rahman@debian:~$ macchanger -s wlp68s0b1 Current MAC: 16:7b:e7:3c:d3:cd (unknown) Permanent MAC: 00:00:00:00:00:00 (FAKE CORPORATION) After reconnecting: rahman@debian:~$ macchanger -s wlp68s0b1 Current MAC: 00:00:00:00:00:00 (FAKE CORPORATION) Permanent MAC: 00:00:00:00:00:00 (FAKE CORPORATION) And so on. With every disconnect I get a different random MAC address which fades on reconnecting, giving me my real MAC address. What causes that and how to stop it? Some outputs: rahman@debian:~$ lspci -nn |grep 14e4 44:00.0 Network controller [0280]: Broadcom Limited BCM4313 802.11bgn Wireless Network Adapter [14e4:4727] (rev 01) rahman@debian:~$ uname -a Linux debian 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u5 (2017-09-19) x86_64 GNU/Linux rahman@debian:~$ sudo ifconfig enp0s25: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether 00:24:c0:7b:a8:8b txqueuelen 1000 (Ethernet) 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 device interrupt 20 memory 0xd4800000-d4820000 enp0s25:avahi: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 169.254.9.109 netmask 255.255.0.0 broadcast 169.254.255.255 ether 00:24:c0:7b:a8:8b txqueuelen 1000 (Ethernet) device interrupt 20 memory 0xd4800000-d4820000 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) RX packets 9436 bytes 6584515 (6.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 9436 bytes 6584515 (6.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlp68s0b1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.5 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::6711:9875:eb78:24fc prefixlen 64 scopeid 0x20<link> inet6 fd9c:c172:b03b:ce00:f1e0:695e:7da0:91a prefixlen 64 scopeid 0x0<global> ether 00:00:00:00:00:00 txqueuelen 1000 (Ethernet) RX packets 484346 bytes 641850809 (612.1 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 368394 bytes 44259668 (42.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 rahman@debian:~$ sudo iwconfig lo no wireless extensions. enp0s25 no wireless extensions. wlp68s0b1 IEEE 802.11 ESSID:"3bdo" Mode:Managed Frequency:2.447 GHz Access Point: 9C:C1:72:B0:3B:D4 Bit Rate=65 Mb/s Tx-Power=30 dBm Retry short limit:7 RTS thr:off Fragment thr:off Encryption key:off Power Management:off Link Quality=54/70 Signal level=-56 dBm Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:4 Invalid misc:183 Missed beacon:0
NetworkManager will reset your MAC address during the Wi-Fi scanning. To permanently change your MAC address: Edit your /etc/NetworkManager/NetworkManager.conf as follows: [main] plugins=ifupdown,keyfile [ifupdown] managed=false [device] wifi.scan-rand-mac-address=no [keyfile] Edit your /etc/network/interfaces by adding the following line: pre-up ifconfig wlp68s0b1 hw ether xx:xx:xx:yy:yy:yy The xx:xx:xx:yy:yy:yy is the new MAC address obtained from the output of macchanger -A wlp68s0b1. Reboot and verify your settings. From Configuring MAC Address Randomization in the Arch Linux wiki: Randomization during Wi-Fi scanning is enabled by default, but it may be disabled by adding the following lines to /etc/NetworkManager/NetworkManager.conf or a dedicated configuration file under /etc/NetworkManager/conf.d: [device] wifi.scan-rand-mac-address=no Setting it to yes results in a randomly generated MAC address being used when probing for wireless networks.
How to stop MAC address from changing after disconnecting?
1,395,122,243,000
I have to extract from the command hcitool dev only the MAC address of the bluetooth dongle. Output of hcitool dev is: Devices: hci0 xx:xx:xx:xx:xx:xx I write this output to a file and try to get the info with awk: hcitool dev > /home/pi/mario/BT.txt awk ' { print $2 } ' /home/pi/mario/BT.txt The output also contains the first row which is an empty cell: xx:xx:xx:xx:xx:xx How can I put off the first cell?
For you purpose is quite enough grep hcitool dev | grep -o "[[:xdigit:]:]\{11,17\}" -o outputs just finded patten [[:xdigit:]:] mean all hexadecimal digits plus : char {11,17} the set of chars should be neither less then 11 no more 17 in length
Extract Bluetooth MAC Address: hcitool dev
1,395,122,243,000
We know that we can use the MAC address to create an interface identifier, e.g. for a link-local IPv6 address which should be unique in the Network. The image shows the way to do this: My questions are: How can I create an IPv6 address from a MAC using awk or sed? OR is there any command that gives me the link-local IPv6 address for a specific MAC (something like that createIPv6 myMAC)?
If you want to create a whole IPv6 address from a MAC (and a given prefix), you could use the excellent ipv6calc tool by Peter Bieringer. The following command creates a link-local IPv6 address (fe80:: prefix) from a MAC address: $ ipv6calc --action prefixmac2ipv6 --in prefix+mac --out ipv6addr fe80:: 00:21:5b:f7:25:1b fe80::221:5bff:fef7:251b You can leave most of the options away and let the command guess what to do: $ ipv6calc --in prefix+mac fe80:: 00:21:5b:f7:25:1b No action type specified, try autodetection...found type: prefixmac2ipv6 fe80::221:5bff:fef7:251b For Debian distros, ipv6calc is in the main repository.
How to use shell to derive an IPv6 address from a MAC address?
1,395,122,243,000
I've made an image of my system and I have given it to someone to run. They have successfully flushed their system with the image and are running it. The problem is as follows: The system normally has 2 Wireless Adapters. Both showing up in the lsusb: pi@raspberry:~ $ lsusb Bus 001 Device 004: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS] Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter I have set the interfaces in the /etc/udev/rules.d/70-persistent-net.rules files by their mac or hw address, and that works fine on my system, but on his system, obviously (while he uses the same type and model of hardware) they are different and as such, his mac address is different, so his 70-persistent-net.rules is useless and is giving him issues. To avoid this in the future, is there a way I can set it so that it perhaps looks for type of model, say: EW-7811Un -> wlan0 SMSC9512 -> wlan1 and sets those, instead on relying on mac address?
First three octets in a MAC address uniquely identify the manufacturer of the device. Udev rules allow you to match any number of characters with an asterisk. Thus, you can write a generic rule that will match any device of a specific vendor: SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="74:2f:68*", NAME="wlan0" Alternatively, you can stop matching on the address and use other parameters instead. Run the following command on both computers: sudo udevadm info -a -p /sys/class/net/wlan0 (substituting the name of the interface, of course), and see what common values you see; then use them in your rules. Writing udev rules is probably the best documentation on the topic.
Cloned system + network interfaces
1,395,122,243,000
With a bash script, can I read the mac address of my eth0 and print it to a file?
ifconfig will output information about your interfaces, including the MAC address: $ ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:11:22:33:44:55 inet addr:10.0.0.1 Bcast:10.0.0.255 Mask:255.0.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:289748093 errors:0 dropped:0 overruns:0 frame:0 TX packets:232688719 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3264330708 (3.0 GiB) TX bytes:4137701627 (3.8 GiB) Interrupt:17 The HWaddr is what you want, so you can use awk to filter it: $ ifconfig eth0 | awk '/HWaddr/ {print $NF}' 00:11:22:33:44:55 Redirect that into a file: $ ifconfig eth0 | awk '/HWaddr/ {print $NF}' > filename
Print mac address to file
1,395,122,243,000
I have set up a network as such: Set up host-only networking on VirtualBox. The first adapter is configured with NAT, the second with host-only networking HOST: Windows GUEST: CentOS VM1, CentOS VM2 (clone of VM1) When executing ifconfig -a on both VMs, I noticed that the MAC addresses are exactly the same. My question is how am I able to ping from VM1 to VM2 considering that the MAC addresses are the same? VM1: eth0 Link encap:Ethernet HWaddr 08:00:27:AF:A3:28 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:feaf:a328/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:27 errors:0 dropped:0 overruns:0 frame:0 TX packets:47 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:10671 (10.4 KiB) TX bytes:5682 (5.5 KiB) eth1 Link encap:Ethernet HWaddr 08:00:27:C4:A8:B6 inet addr:192.168.56.102 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fec4:a8b6/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:859 errors:0 dropped:0 overruns:0 frame:0 TX packets:41 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:114853 (112.1 KiB) TX bytes:4823 (4.7 KiB) ip -6 addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000 inet6 fe80::a00:27ff:feaf:a328/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000 inet6 fe80::a00:27ff:fec4:a8b6/64 scope link valid_lft forever preferred_lft forever VM2: eth0 Link encap:Ethernet HWaddr 08:00:27:AF:A3:28 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:feaf:a328/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:114 errors:0 dropped:0 overruns:0 frame:0 TX packets:151 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:41594 (40.6 KiB) TX bytes:13479 (13.1 KiB) eth1 Link encap:Ethernet HWaddr 08:00:27:C4:A8:B6 inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fec4:a8b6/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1900 errors:0 dropped:0 overruns:0 frame:0 TX packets:78 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:259710 (253.6 KiB) TX bytes:9736 (9.5 KiB) ip -6 addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000 inet6 fe80::a00:27ff:feaf:a328/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000 inet6 fe80::a00:27ff:fec4:a8b6/64 scope link tentative dadfailed valid_lft forever preferred_lft forever
This is one of those things that surprises people because it goes against what they've been taught. 2 machines with the same hardware mac address on the same broadcast domain can talk to each other just fine as long as they have different IP addresses (and the switching gear plays nice). Lets start with a test setup: VM1 $ ip addr show dev enp0s8 3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:3c:f9:ad brd ff:ff:ff:ff:ff:ff inet 169.254.0.2/24 scope global enp0s8 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe3c:f9ad/64 scope link valid_lft forever preferred_lft forever   VM2 $ ip addr show dev enp0s8 3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:3c:f9:ad brd ff:ff:ff:ff:ff:ff inet 169.254.0.3/24 scope global enp0s8 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe3c:f9ad/64 scope link tentative dadfailed valid_lft forever preferred_lft forever So notice how both machines have the same MAC addr, but different IPs. Lets try pinging: VM1 $ ping -c 3 169.254.0.3 PING 169.254.0.3 (169.254.0.3) 56(84) bytes of data. 64 bytes from 169.254.0.3: icmp_seq=1 ttl=64 time=0.505 ms 64 bytes from 169.254.0.3: icmp_seq=2 ttl=64 time=0.646 ms 64 bytes from 169.254.0.3: icmp_seq=3 ttl=64 time=0.636 ms --- 169.254.0.3 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 0.505/0.595/0.646/0.070 ms So, the remote host responded. Well, that's weird. Lets look at the neighbor table: VM1 $ ip neigh 169.254.0.3 dev enp0s8 lladdr 08:00:27:3c:f9:ad REACHABLE 10.0.2.2 dev enp0s3 lladdr 52:54:00:12:35:02 STALE That's our MAC! Lets do a tcpdump on the other host to see that it's actually getting the traffic: VM2 $ tcpdump -nn -e -i enp0s8 'host 169.254.0.2' 16:46:21.407188 08:00:27:3c:f9:ad > 08:00:27:3c:f9:ad, ethertype IPv4 (0x0800), length 98: 169.254.0.2 > 169.254.0.3: ICMP echo request, id 2681, seq 1, length 64 16:46:21.407243 08:00:27:3c:f9:ad > 08:00:27:3c:f9:ad, ethertype IPv4 (0x0800), length 98: 169.254.0.3 > 169.254.0.2: ICMP echo reply, id 2681, seq 1, length 64 16:46:22.406469 08:00:27:3c:f9:ad > 08:00:27:3c:f9:ad, ethertype IPv4 (0x0800), length 98: 169.254.0.2 > 169.254.0.3: ICMP echo request, id 2681, seq 2, length 64 16:46:22.406520 08:00:27:3c:f9:ad > 08:00:27:3c:f9:ad, ethertype IPv4 (0x0800), length 98: 169.254.0.3 > 169.254.0.2: ICMP echo reply, id 2681, seq 2, length 64 16:46:23.407467 08:00:27:3c:f9:ad > 08:00:27:3c:f9:ad, ethertype IPv4 (0x0800), length 98: 169.254.0.2 > 169.254.0.3: ICMP echo request, id 2681, seq 3, length 64 16:46:23.407517 08:00:27:3c:f9:ad > 08:00:27:3c:f9:ad, ethertype IPv4 (0x0800), length 98: 169.254.0.3 > 169.254.0.2: ICMP echo reply, id 2681, seq 3, length 64 So, as you can see, even though the traffic has the same source and destination hardware mac address, everything still works perfectly fine. The reason for this is that the MAC address lookup comes very late in the communication process. The box has already used the destination IP address, and the routing tables to determine which interface it is going to send the traffic out on. The mac address that it adds onto the packet comes after that decision. I should also note that this is dependent upon the layer 2 infrastructure. How these machines are connected, and what sits between them. If you've got a more intelligent switch, this may not work. It may see this packet coming through and reject it. Now, going on to the traditional belief, of that this doesn't work. Well it is true, from a certain point of view :-) The problem arises when another host on the network needs to talk to either of these machines. When the traffic goes out, the switch is going to route the traffic by the destination mac address, and it's only going to send it to a single host. There are a few possible reasons why this test setup works: The traffic is broadcast to all ports, or to all ports which the MAC matches. The switch discards the source port as an option when determining the destination port. The switch is actually a layer 3 switch and is routing based on the IP address, and not the mac address.
Identical MAC address on two different VM, yet I have internet connectivity
1,395,122,243,000
Per this comment, I'm going to take advice and ask this as a separate question. I am trying to learn more about networking and security and want to play with tools to help increase my understanding. Fing seems like a pretty cool tool - finding devices on the network and their associated MAC address. One could easily implement any of the solutions that provides detection and alerting, but I would like to know how these tools are implemented? Is this a combination of low level linux utilities, or is there some custom programming going on? If it is the second - what would that algorithm look like?
I just ran Fing against my wireless network. Using tcpdump, it appears that Fing generates Address Resolution Protocol (ARP) request packets. ARP is a pretty simple protocol that runs at the Ethernet Protocol level (Data Link, OSI level 2). An ARP request packet has the broadcast address (ff:ff:ff:ff:ff:ff) as the "to" address, the Android phone's MAC and IP address as the "from" information, and an IP address that Fing wants to know about. It appears that Fing just marches through whatever subnet it's on, in my case 172.31.0.0/24, so 255 IP addresses, from 172.31.0.1 to 172.31.0.254. After the march, it appears to try IP addresses that haven't responded a second time. This looks to me like Fing tries IP addresses in batches, and relies on the underlying Linux kernel to buffer ARP replies, for a Fing thread to deal with as fast as it can. If Fing decides that there's a timeout, it resends. It's not clear to me how Fing (a Java program) gets the phone's Linux kernel to generate ARP packets. The notorious nmap, invoked with -sn, the "ping scan" flag, does the same thing. I did an strace on nmap -sn 172.31.0.0/24 to see how it gets the kernel to send ARP requests. It looks like nmap creates an ordinary TCP/IP socket, and calls connect() on the socket to TCP port 80, with an IP address. nmap must be doing this in non-blocking mode, as it does a large number of connect() calls sequentially, faster than it would take for Linux to decide to time out a connect() when there's no host with the IP address. So there's your answer: create a TCP/IP socket, call connect() with a particular port and IP address, then see what the error is. If the error is ECONNREFUSED, it's a live IP address, but nothing is listening on that port. If you get a TCP connection, that IP address has a host. IP addresses that the connect() call times out for, don't have a machine associated. You need to batch the connect() calls for speed, and you need to wait for connect() calls to timeout to decide that an IP address does not have a machine associated with it.
How does FING (or any of the IP/MAC Address Mappers) work?
1,395,122,243,000
In Red Hat Enterprise Linux (RHEL) 8, if someone does ifconfig eth0 hw ether abcd12341234, all I know is ifconfig and ip -a, so then is there a way to reliably get the real MAC address of that eth0 interface and if so how? ... other than for example rebooting to a Linux live CD coming from a reliable source to be sure the MAC address of the interface hasn't been changed.
This answer is about Linux. ifconfig is obsolete and doesn't have access to a kernel API able to provide it this information. This information has been able to be retrieved for a long time with ethtool --show-permaddr. Example (redacted): # ethtool --show-permaddr eth0 Permanent address: 10:1f:74:32:10:fe Some board/firmware/driver combination might not have a permanent address and the result could be like this: # ethtool --show-permaddr eth0 Permanent address: not set A recent enough ip link/kernel will provide (possibly through an other API) the permanent address whenever the current address differs from an existing permanent address if it is set. For example (redacted): # ip link set dev eth0 address 12:34:56:78:9a:bc $ ip link show dev eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether 12:34:56:78:9a:bc brd ff:ff:ff:ff:ff:ff permaddr 10:1f:74:32:10:fe Here permaddr 10:1f:74:32:10:fe represents the original MAC address. It's provided only when the current MAC address differs from the permanent MAC address. Such change could also have happened temporarily for example when an interface is set as a bond slave and (depending on its mode) inherits the bond's MAC address. To retrieve it programmatically, even when it was not changed, better use the JSON output and jq, for example like this: ip -json link show dev eth0 | jq -r '.[] | .permaddr // .address' which retrieves the permanent MAC address or if not provided the MAC address (which means it's the unchanged permanent MAC address... unless there is none, in which case it's the current). If this matters, one must first be sure there is a permanent address, because contrary to ethtool it doesn't appear to allow to know there is no known permanent address set for the board/firmware/driver combination.
How to find unspoofed MAC address of NIC
1,395,122,243,000
I am looking for a way to mask the client MAC address every time it appears in a logfile before using the logfile to present data to a customer (GDPR rules). I can identify the MAC string using regex, but am unsure what the best way of masking is, since MD5 seems to be advised against as it's almost transparent! I need a given MAC to always return the same mask/uuid since MACs will be coming in at various times and I need to track a given MAC as it goes through the system. regex used is (?<=clientMac":\s")[A-Z0-9]{12} Ideally I'd like to use something simple like sed to make the substitution but I accept it may not be possible.
As requested in the comment, here is an example how to perform such a substitution with sed. You used the /linux tag, so it should be safe to use GNU sed with its e flag for the s command: sed -E 'h;s/.*clientMac":\s"([A-Z0-9]{12}).*/echo secretKey\1|md5sum/e;T G;s/(.*)\s*-\n(.*clientMac":\s")[A-Z0-9]{12}(.*)/\2\1\3/' logfile Explanation: The h command saves the line to the hold space, so we can restore it after messing up the line (-; s/.*clientMac":\s"([A-Z0-9]{12}).*/echo secretKey\1|md5sum/e matches the whole line, putting the actual MAC in () to be reused in the replacement. The replacement forms the command to be executed: echoing the MCA along with the "salt" and piping it into md5sum. The e flag makes sed execute this in the shell and putting the result in the buffer again T branches to the end of the script if no replacement was made. This is to print lines without MAC unmodified. Following lines are executed only if a replacement was made G appends the original line from the hold buffer, so now we have the md5sum output, a newline and the original line in the buffer s/(.*)\s*-\n(.*clientMac":\s")[A-Z0-9]{12}(.*)/\2\1\3/ captures the MD5 in the first pair of (), the line before the MAC in the second and the rest of the line after the MAC in the third, thus \2\1\3 replaces the MAC with the MD5
Replace MAC address with UUID
1,395,122,243,000
I have just upgraded two servers from Debian 10 (Buster) to Debian 11 (Bullseye). Afterwards, I could not reach either of them via the network any more. After some investigation, the following problem turned out: Both machines have a bridge device configured. Obviously, the algorithm which Debian uses to assign MAC addresses to bridge devices has changed from version 10 to 11. After the upgrade, the bridge device on the first server had the same MAC address as the bridge device on the second server, which for sure has not been the case before. One of the answers there claims that a bridge is a purely internal device and that therefore a bridge's MAC address does not matter. However, this is obviously wrong. At least in my case, packets from both machines were outgoing with the hardware source address being the bridge's MAC address, and the network ports on both machines were processing incoming packets only if they were destined for the bridge's MAC address. Since that MAC address was the same on both machines, the network became unusable, which is completely logical and understandable. How can I make Debian generate different MAC addresses for bridge devices which are on different machines (or even on the same machine, but that's currently not my issue)?
Browsing in Internet I found this bug report on systemd-udev related to Debian 11 bridges: systemd-udev interferes with MAC addresses of interfaces it's not supposed to do #21185: ash.in.ffho.net:~# for n in 0 1 2 3; do ip l add br$n type bridge; done ash.in.ffho.net:~# ip -br l br0 DOWN d2:9e:b3:32:53:42 <BROADCAST,MULTICAST> br1 DOWN e2:00:44:2c:5b:70 <BROADCAST,MULTICAST> br2 DOWN 0e:99:b7:42:f0:25 <BROADCAST,MULTICAST> br3 DOWN a6:3f:5f:b5:9a:d6 <BROADCAST,MULTICAST> ash.in.ffho.net:~# for n in 0 1 2 3; do ip link del br${n}; done ash.in.ffho.net:~# for n in 0 1 2 3; do ip l add br$n type bridge; done ash.in.ffho.net:~# ip -br l br0 DOWN d2:9e:b3:32:53:42 <BROADCAST,MULTICAST> br1 DOWN e2:00:44:2c:5b:70 <BROADCAST,MULTICAST> br2 DOWN 0e:99:b7:42:f0:25 <BROADCAST,MULTICAST> br3 DOWN a6:3f:5f:b5:9a:d6 <BROADCAST,MULTICAST> As you can see, the bridges were created with low-level commands, but they always inherit the same MAC address value: a systemd component interferes and sets the MAC address. One can see this in action using ip monitor link: 22: brtest0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default link/ether 0a:ae:c3:0d:ec:68 brd ff:ff:ff:ff:ff:ff 22: brtest0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default link/ether 1a:d0:fc:63:c1:71 brd ff:ff:ff:ff:ff:ff Deleted 22: brtest0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default link/ether 1a:d0:fc:63:c1:71 brd ff:ff:ff:ff:ff:ff 23: brtest0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default link/ether 4e:e9:11:dd:a5:aa brd ff:ff:ff:ff:ff:ff 23: brtest0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default link/ether 1a:d0:fc:63:c1:71 brd ff:ff:ff:ff:ff:ff You can see how the MAC address initially random is overwritten to a fixed one, twice to the same value for a given bridge name. An other side effect is that when interface is set administratively UP, the bridge operational status becomes DOWN instead of UNKNOWN initially because of this (see these answers of mine on SU and SF mentioning behaviors about DOWN and UNKNOWN: How does Linux determine the default MAC address of a bridge device? , linux ipv6 bridge address does not work when mac address is forced). Anyway this doesn't matter anymore once its first bridge port is attached. Doing the same experiment inside a network namespace (eg: ip add netns experiment and ip netns exec experiment bash -l before running above commands twice) where systemd-udevd does not interfere will show the usual behavior of having different random addresses each time. This is an effect of systemd ecosystem and doesn't happen on systems not running systemd (or older versions of systemd). One proposed fix is to use: # /etc/systemd/network/90-bridge.link [Match] OriginalName=br* [Link] MACAddressPolicy=random but it appears the real fix is to change the file that participates in generating this "stable random" value, as described there: https://wiki.debian.org/MachineId Each machine should have a different value. This is especially important for cloned VMs from a base template. The relation between machine-id and the way the bridge "stable" MAC address is generated is mentioned in the patch having implemented the (quite breaking) change: === This patch This patch means that we will set a "stable" MAC for pretty much any virtual device by default, where "stable" means keyed off the machine-id and interface name. It was also mentioned that this would be having impacts , but this was shrugged off. This is not limited to interfaces of type bridge but to any interface that would generate a random MAC address: for example types veth, macvlan tuntap are also affected. I could verify that the same bridge name would get a different "stable random" value after doing the operations described in Debian's link: rm -f /etc/machine-id /var/lib/dbus/machine-id dbus-uuidgen --ensure=/etc/machine-id dbus-uuidgen --ensure giving now in previous ip monitor a new MAC address for the same bridge name: 32:ee:c8:92:9f:e8 instead of 1a:d0:fc:63:c1:71 when deleting and recreating brtest0. Deleted 23: brtest0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default link/ether 1a:d0:fc:63:c1:71 brd ff:ff:ff:ff:ff:ff 24: brtest0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default link/ether da:72:b6:63:23:e5 brd ff:ff:ff:ff:ff:ff 24: brtest0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default link/ether 32:ee:c8:92:9f:e8 brd ff:ff:ff:ff:ff:ff Conclusion: Because the bridge MAC address is now manually set the bridge won't inherit anymore one of the MAC addresses of other interfaces set as bridge ports, including the usual permanent (physical or VM's) interfaces which are expected to have each a different MAC address. Two systems using the same machine-id and the same bridge name (eg: br0) with such bridge participating in routing (ie: there's an IP address configured on the bridge, but even if not the bridge can emit other frames related to bridging depending on its settings) on the same LAN will emit frames with the same source MAC address (bridge's), possibly disrupting switches in the path and anyway ignoring such same source MAC address from the peer.
How can I make Linux generate different MAC addresses for different bridge devices which are on different PCs?
1,395,122,243,000
Sometimes I need to spoof MAC address, I'm doing so with this command: ip link set dev eth0 address XX:XX:XX:XX:XX:XX Is there a way how to set MAC address back to default without reboot?
See also: sudo ethtool -P eth0 So, to set the MAC address back to its default (assuming GNU grep here): set_to_real() ( for i do mac=$(ethtool -P "$i" | grep -iEom1 '([0-9a-f]{2}:){5}[0-9a-f]{2}') && ip link set dev "$i" address "$mac" done ) set_real eth0
Set MAC address to default
1,395,122,243,000
I'm scratching my head about this question... I have a debian squeeze machine that is connected to an internal lab network. We have a lot of machines that have default proxy-arp configurations on them, and occasionally one of those machines starts hijacking a lot of lab addresses. After resolving the latest Proxy-ARP incident which brought down most of our lab, I found a few residual entries like this in /var/log/syslog (below). For those not accustomed to reading arpwatch logs, the machine that owns 00:11:43:d2:68:65 is fighting with 192.168.12.102 and 192.168.12.103 about who owns those address. Sep 13 14:25:27 netwiki arpwatch: flip flop 192.168.12.103 00:11:43:d2:68:65 (84:2b:2b:4b:71:b4) eth0 Sep 13 14:26:24 netwiki arpwatch: flip flop 192.168.12.103 84:2b:2b:4b:71:b4 (00:11:43:d2:68:65) eth0 Sep 13 14:29:03 netwiki arpwatch: flip flop 192.168.12.102 00:26:b9:4e:d3:71 (00:11:43:d2:68:65) eth0 Sep 13 14:29:03 netwiki arpwatch: flip flop 192.168.12.102 00:11:43:d2:68:65 (00:26:b9:4e:d3:71) eth0 The very alarming thing is that 00:11:43:d2:68:65 belongs to the same machine I was running arpwatch on... First, I validated that /proc/sys/net/ipv4/conf/eth0/proxy_arp is 0. Next, I used tshark to validate that my machine really is spoofing ARPs to others... [mpenning@netwiki ~]$ ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:11:43:d2:68:65 brd ff:ff:ff:ff:ff:ff inet 192.168.12.239/24 brd 192.168.12.255 scope global eth0 inet6 fe80::211:43ff:fed2:6865/64 scope link valid_lft forever preferred_lft forever [mpenning@netwiki ~]$ [mpenning@netwiki ~]$ arp -an ? (192.168.12.46) at 00:15:c5:f5:81:9d [ether] on eth0 ? (192.168.12.236) at 00:1e:c9:cd:46:c8 [ether] on eth0 ? (10.211.180.1) at 00:1e:49:11:fe:47 [ether] on eth1 ? (192.168.12.20) at f0:4d:a2:02:81:66 [ether] on eth0 [mpenning@netwiki ~]$ cat /proc/sys/net/ipv4/conf/eth0/proxy_arp 0 [mpenning@netwiki ~]$ sudo tshark -i eth0 arp and ether src 00:11:43:d2:68:65 Running as user "root" and group "root". This could be dangerous. Capturing on eth0 0.000000 Dell_d2:68:65 -> Dell_02:81:66 ARP 192.168.12.102 is at 00:11:43:d2:68:65 84.954989 Dell_d2:68:65 -> Dell_f5:81:9d ARP 192.168.12.103 is at 00:11:43:d2:68:65 [mpenning@netwiki ~]$ uname -a Linux netwiki 2.6.32-5-amd64 #1 SMP Tue Jun 14 09:42:28 UTC 2011 x86_64 GNU/Linux [mpenning@netwiki ~]$ The facts are undeniable. I have a debian box that is spoofing ARPs and I have no idea why. I am the only user on this machine, I run fail2ban to prevent brute-force attacks, and it's on an internal lab network behind a door that requires a badge for entry; I highly doubt it has been hacked. Three questions... First, is there any cause I may have missed? What steps should I use to isolate whether this is an application or kernel problem? If this is a kernel bug, which mailing-list should I report it on? FYI, the normal kernel.org bug reporting tool seems to be down right now. Is there anything I can do to to solve the problem other than waiting for a patch?
I found the problem... I was demonstrating how proxy-arp worked on a spare ethernet interface a few weeks ago and left the configs on the machine (although I had the interface DOWN). When I removed these entries for 192.168.12.0/24 from eth2, I no longer had the problem. [mpenning@netwiki ~]$ ip add show eth2 4: eth2: <BROADCAST,MULTICAST,PROMISC> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 00:10:18:02:32:86 brd ff:ff:ff:ff:ff:ff inet 192.168.12.100/24 scope global eth2 inet 192.168.1.100/24 scope global eth2 inet 192.168.12.101/24 scope global secondary eth2 inet 192.168.12.102/24 scope global secondary eth2 inet 192.168.12.103/24 scope global secondary eth2 inet 192.168.12.104/24 scope global secondary eth2 inet 192.168.12.105/24 scope global secondary eth2 [mpenning@netwiki ~]$ I still think this is a bug and it needs to be filed. I will update with the bug information when it is completed.
eth0 is proxy-arping, but /proc/sys/net/ipv4/conf/eth0/proxy_arp is 0
1,395,122,243,000
I need to read permanent (burned-in) MAC address of network adapter. Since MAC address can be easily spoofed, I need to read the real one which is written on EEPROM. I need to do it using C++ on Linux. I tried using ethtool which is quite good and works fine. However on some systems it does not work as intented. ethtool -P eth0 returns this: Permanent address: 00:00:00:00:00:00 and ethtool -e eth0 returns this: Cannot get EEPROM data: Operation not supported Network Adapter has following info: driver: ucc_geth version: 1.1 firmware-version: N/A bus-info: QUICC ENGINE Linux kernel version is: 2.6.32.13 Question is: Can i fix this issue with any update(driver, kernel etc)? Additionally, I make the same ethtool calls with ioctl function in C++. Is there any way to fix this inside the code? Or is there any other way to get the permanent MAC address from EEPROM?
If you trust the local machine not to be spoofing, both ifconfig and ip addr will give you the MAC address of the hardware. If you don't trust the local machine, neither ethtool, ifconfig, nor ip is going to provide you the information you need. Because there are very legitimate reasons for MAC spoofing (for example, hot-fail on ethercards) all the drivers report only the currently "virtual" MAC address because if you need to spoof the address it wouldn't do well for some of the tools to report the firmware address and others to report the soft address. No ioctl can or should give you the hard-address. To get the hard-address requires reading the device registers directly and is thus completely device specific. A quick look through the ucc_geth.c driver seems to show that MAC address reassignment is supported by the chip itself (which makes sense as it needs to be able to pluck packets sent to its soft address off the ether). This means that you need to be very deliberate to ensure you are getting the hard address for which the driver liberally says: /* For more details see the hardware spec. */
ethtool get permanent MAC address returns all 0's
1,395,122,243,000
we are trying to add a static ARP entry to a FreeBSD system. This works well with, for example, arp -S 172.16.16.9 11:54:33:A8:B2:6B . We have added this to a startup script to survive a reboot. So far so good. However, if the physical link is cycled, the permanent ARP entry is flushed, too. Does anybody know of a. A good way to prevent this or b. A good way to re-add on link-up or c. A better way altogether?
Becoming friends with FreeBSD You seem to be on a partially correct path. I presume you have a lot of knowledge on Unix but not so much an actual FreeBSD system. The reason I am guessing this is you have approached it in a slightly different way than the typical user of rc.d in FreeBSD. I find the question a bit thin as I personally would rather chase why the arp goes missing. But we are given precious little information. Instead we jump to conclusions. They do however pose some interesting questions on how to do stuff on FreeBSD. Just bear in mind the huge caveat emptor that we might end up using a wrench as a hammer. Writing rc scripts The FreeBSD startup scripts live in /etc/rc.d but you should never create anything there but leave that directory to the Operating System. Otherwise you risk having your things overwritten during an update. If you want to write your own startup/daemon/service scripts then the best location would be in /usr/local/etc/rc.d Recommended file locations are documented in hier And rather than writing everything from scratch you can get a lot of helper functions by reading Practical rc.d scripting in BSD /etc/rc.conf.d/* You ask in a comment if you can use it in a script in /etc/rc.conf.d/*. Please please do not do this. Files from here are sourced at startup - but the purpose for this directory is to have small snippets with configuration settings (see rc.conf). Most people simply use the file /etc/rc.conf to configure the system options - but you can split these into small segments and put them into /etc/rc.conf.d even though it is not as common. It would be better to put your more generic statup script in /etc/rc.local which is still supported. But I would still recommend creating a proper rc script and put it in /usr/local/etc/rc.d If you want to ignore rc scripts altogether another common way to start a generic script at boot is to use the @reboot keyword in crontab I would however say that you do not need to create a new rc script as the functionality is already there. static_arp Static arp is actually well documented - it is however very simple. The "missing" documentation might be how rc scripts are handled. It is documented in rc.conf: static_arp_pairs (str) Set to the list of static ARP pairs that are to be added at system boot time. For each whitespace separated element in the value, a static_arp_<element> variable is assumed to exist whose contents will later be passed to a ``arp -S'' operation. For example static_arp_pairs="gw" static_arp_gw="192.168.1.1 00:01:02:03:04:05" This means that you can add 3 static arp entries which will survive reboot by adding these lines to /etc/rc.conf (I recommend using the sysrc command): static_arp_pairs="a b c" static_arp_a="1.2.3.4 11:22:33:44:55:66" static_arp_b="1.2.3.5 22:33:44:55:66:77" static_arp_c="1.2.3.6 33:44:55:66:77:88" Or in your specific case: static_arp_pairs="myarp" static_arp_myarp="172.16.16.9 11:54:33:A8:B2:6B" The script handling this is part of the OS and is placed in /etc/rc.d/static_arp and is very simple. It only supports "start" and "stop" commands. You can call it from anywhere using: /etc/rc.d/static_arp start But I would prefer using the service command: service static_arp start If for some reason you feel tempted to edit/change /etc/rc.d/static_arp then please do not! Root is omnipotent and you can do what you want - but you risk it will be replaced. What you should do is cp /etc/rc.d/static_arp /usr/local/etc/rc.d/mystatic_arp and have the modified version live there. Notice the name change and make sure it is reflected within the script! Recycling physical link If you are used to other systems you might simply be taking the interface up/down using ifconfig. But on FreeBSD you should consider using: service netif restart <interface> I have honestly not tested if this brings the static_arp along as well. Or something along the lines of: service netif stop <interface> ... service netif start <interface> service routing restart service static_arp start But cycling the physical link could be (un)plugging the cable? Again I am not sure what happens to the arp table then. I would expect it to still be in place as we have not put down the interface administratively. UPDATE: @namezero has confirmed in a comment that arp entires set with static_arp do survive physical disconnects. But we should examine this a little further to fully understand your case. This is then as close as I can get to answer "a. A good way to prevent this" cron If we get no notification of the physical link - then I do not see a better way than monitoring it. If we keep the script simple - then we can leave it to a regular cron. devd to the rescue If we are able to see the change from the OS then we have a nice path forward. The device state change daemon devd comes in handy. Your description is lacking so I will then assume that we either have a LINK_UP or a LINK_DOWN to act on. Create the file /etc/devd/interface.conf with the content: notify 0 { match "system" "IFNET"; match "subsystem" "(em0|em1)"; match "type" "LINK_DOWN"; action "/usr/local/sbin/alertme.sh $subsystem" } This will notify you for the network interfaces em0 and em1. So it could be as simple as: notify 0 { match "system" "IFNET"; match "subsystem" "(em0|em1)"; match "type" "LINK_UP"; action "/etc/rc.d/static_arp start" } This does however feel a bit of a kludge to me as I would spend more time discovering why the arp entries are missing. But I hope these different pointers can get you in "some" direction. Summary This brings us to this shortlist which outlines how you can live a happier life with FreeBSD: System settings should live in /etc/rc.conf If you want your own rc scripts put them in /usr/local/etc/rc.d If you want a simple startup script put it in /etc/rc.local (you can source rc if you want) If you want a truly generic script at startup use @reboot with crontab Use sysrc when editing /etc/rc.conf Use service when interacting with rc scripts Use devd acting on device state changes
FreeBSD static ARP entry when link cycles
1,395,122,243,000
Question: I would like to find a way to have the HWADDR line in the ifcfg-eth0 script verify/update itself on-boot in case it changes when a clone or copy of the VM occurs. Is there a way to do so? In CentOS 6, removing the HWADDR line from the ifcfg-eth0 script made it much more dynamic, but I have yet to find a way to keep ifcfg-eth0 from changing back to ifcfg-eno1677776 without the HWADDR line in CentOS 7. Thanks in advance for the help! Background: I am running a CentOS 7.2.1511 virtual machine via VMware Workstation. By default CentOS 7 got rid of the eth0 naming convention of its network scripts and is now configured to use network scripts named ifcfg-eno1677776 or something similar. I have software that heavily relies on the eth0 naming scheme. So I have re-configured my ifcfg-eno1677776 script by: Renaming /etc/sysconfig/network-scripts/ifcfg-eno1677776 to /etc/sysconfig/network-scripts/ifcfg-eth0 Modifying ifcfg-eth0 to be (got HWADDR from /sys/class/net/eno1677776/address): BOOTPROTO=dhcp NAME=eth0 DEVICE=eth0 ONBOOT=yes NM_CONTROLLED=no HWADDR=00:0c:29:d6:d2:65 Added net.ifnames=0 to the end of the GRUB_CMDLINE_LINUX line in the /etc/sysconfig/grub file. Reboot and run ifconfig (and celebrate!): eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.176.15.148 netmask 255.255.252.0 broadcast 10.176.15.255 inet6 fe80::20c:29ff:fed6:d265 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:d6:d2:65 txqueuelen 1000 (Ethernet) RX packets 2141073 bytes 749959853 (715.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 65237 bytes 35352127 (33.7 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 Each time I boot, this eth0 interface remains. However, this VM is to be distributed between team members and eventually delivered to customers. This is where the problem arises. VMware is great in that you can clone a snapshot of a VM for distribution, but this changes the MAC address of the VM. EDIT: You must run grub2-mkconfig -o /boot/grub2/grub.cfg after making the change @larsks recommended below for it to work. Worked for me!
The easiest solution is probably to disable the "predictable device naming" behavior by setting the following options on your kernel command line: biosdevname=0 net.ifnames=0 With this in place, the first ethernet interface on your system will be named eth0, the second will be eth1, etc. This is documented here. With this in place, just remove the HWADDR line from your configuration file and everything should work as you expect.
Forcing HWADDR to correct itself in ifcfg-eth0 network script on boot CentOS 7
1,395,122,243,000
I have a server in an internal network (login there via VPN) from where I login to the server via SSH with OpenSSH public/private key authentication. From a security point of view, I want to tie the MAC addresses of my three used clients via iptables on the server so that only these clients can login with it. iptables -A INPUT -p tcp --destination-port 22 -m mac --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT iptables -A INPUT -p tcp --destination-port 22 -j DROP However, is it recommended though to do it this way? What other (better) methods can I use to tie the SSH login to the used clients? (If someone wants to request 2FA, unfortunately 2FA is not possible as potential solution.) Thanks.
I am supposing that you want to prevent your SSH server from accepting connections from untrusted hosts even though they supply valid user credentials. Is it right? A possible solution to tie users' public key authentication to selected client hosts is via host-based authentication. By setting up host-based authentication and defining AuthenticationMethods parameter in /etc/ssh/sshd_config to either: AuthenticationMethods hostbased,publickey hostbased,keyboard-interactive hostbased,password Or: AuthenticationMethods hostbased,publickey That will instruct SSH daemon to request clients to authenticate the hosts they are connecting from before checking users' keys or passwords. The former alternative allows password-based authentication, while the latter restricts it to public keys only. Since host-based authentication is based on keypairs, SSH server will be able to authenticate clients with dynamic IP addresses. Here follows complete instructions. The documentation of how SSH performs host-based authentication is written in ssh(1) man-page. Please note how SSH identifies users and check whether it is applicable to your case. Host-based authentication works as follows: If the machine the user logs in from is listed in /etc/hosts.equiv or /etc/ssh/shosts.equiv on the remote machine, and the user names are the same on both sides, or if the files ~/.rhosts or ~/.shosts exist in the user's home directory on the remote machine and contain a line containing the name of the client machine and the name of the user on that machine, the user is considered for login. Additionally, the server must be able to verify the client's host key for login to be permitted. This authentication method closes security holes due to IP spoofing, DNS spoofing, and routing spoofing. [Note to the administrator: /etc/hosts.equiv, ~/.rhosts, and the rlogin/rsh protocol in general, are inherently insecure and should be disabled if security is desired.] To enable host-based authentication in OpenSSH: Set the following parameter values in /etc/ssh/sshd_config: # /etc/ssh/sshd_config HostbasedAuthentication yes IgnoreUserKnownHosts yes IgnoreRhosts yes # AuthenticationMethods hostbased,publickey hostbased,keyboard-interactive hostbased,password AuthenticationMethods hostbased,publickey To perform host-based authentication, you can trust the hostname information supplied by clients by setting HostbasedUsesNameFromPacketOnly yes in /etc/ssh/sshd_config: # /etc/ssh/sshd_config HostbasedUsesNameFromPacketOnly yes Or, alternatively, you can configure SSH daemon to identify hostnames via resolution of clients' IP addresses using information stored in either /etc/hosts file or PTR records in network's DNS server: # /etc/ssh/sshd_config HostbasedUsesNameFromPacketOnly no UseDNS yes List the hostnames of the authorized clients in /etc/ssh/shosts.equiv file. Create it manually if it doesn't exist. The syntax of the file is almost the same as documented in man host.equiv(5), however SSH daemon does not accept empty hostnames. # /etc/ssh/shosts.equiv ssh-client-alpha ssh-client-bravo ssh-client-charlie List the public keys of the authorized hosts in /etc/ssh/ssh_known_hosts file. A convenient way to do so is via ssh-keyscan: [root@ssh-server ~]# ssh-keyscan ssh-client-alpha >> /etc/ssh/ssh_known_hosts [root@ssh-server ~]# ssh-keyscan ssh-client-bravo >> /etc/ssh/ssh_known_hosts [root@ssh-server ~]# ssh-keyscan ssh-client-charlie >> /etc/ssh/ssh_known_hosts After configuring OpenSSH server to accept host-based authentication requests, clients must also be configured to request host-based authentication: Set the following parameter values in /etc/ssh/ssh_config: # /etc/ssh/ssh_config Host * HostbasedAuthentication yes EnableSSHKeySign yes Ensure that SUID/SGID bits in ssh-keysign executable grant read permission to host's private key files: [root@ssh-client-alpha ~]# find /usr -name ssh-keysign -ls 16517300 616 -r-xr-sr-x 1 root ssh_keys 630344 Feb 4 16:01 /usr/libexec/openssh/ssh-keysign [root@ssh-client-alpha ~]# ls -l /etc/ssh/ssh_host_*key -rw-r----- 1 root ssh_keys 480 Apr 13 06:51 /etc/ssh/ssh_host_ecdsa_key -rw-r----- 1 root ssh_keys 387 Apr 13 06:51 /etc/ssh/ssh_host_ed25519_key -rw-r----- 1 root ssh_keys 2578 Apr 13 06:51 /etc/ssh/ssh_host_rsa_key
SSH with MAC based filtering using iptables - recommended?
1,395,122,243,000
I know that I can change a network interface's MAC address by bringing the interface down, using a command like ifconfig eth0 hw ether 00:11:22:33:44:55 or ip link set eth0 address 00:11:22:33:44:55 and then bringing the interface up again. A command like ip link show eth0 then confirms that the change was successful. But I recently discovered the files in /sys/class/net (originally from this answer): each one is a symbolic link to a directory containing files with information about the interface as documented here For example, on my machine, the ethernet interface is enp3s0 (I have no idea why it has such a strange name), and /sys/class/net/enp3s0 links to /sys/devices/pci0000:00/0000:00:1c.2/0000:03:00.0/net/enp3s0. In this directory, I then found the file address which is just a text file containing the MAC address of the interface. But when I attempt to change the address using one of the commands above, the address file stays the same, so apparently, the commands do not change the MAC address on the lowest level. It is also not possible to change this file in any manner, not even the superuser has permission to do this. So now, just out of curiosity: Is it possible to change the MAC address of a network interface on this level?
Background /proc and /sys filesystems are just a view of kernel structures, both filesystems reside in memory. Although both filesystems are writable (well, some of the files in there are writable) it is unwise to assume that they behave the same way as a real filesystems. Operations that allow you to write into a file inside /proc or /sys end as hooks and then as function calls. For example: # echo 3 > /proc/sys/vm/drop_caches Does not really write to that file, it calls a userspace kernel function. If a function is not defined for a certain write you will get: write error: Input/output error That is because it does not make sense to write to that file. It is not that different from writing to the character device of a USB device that has no driver associated to. The kernel does not know what to do. There is no function defined for writes against /sys/class/net/enp3s0/address, therefore that is not a viable route to change the MAC address of that interface. Can I change the MAC address without calling ifconfig or ip link set ? Yes, you can. If you look at the code for iproute2 you will find a lot of argument parsing and a call to rtnl_talk. It looks as follows (this is from the ip/iplink.c file): /* lot of argument parsing and `req` setting */ if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) exit(2); return 0; req.n in there is the MAC address being passed to rnetlink function rtnl_talk (man rnetlink is relevant here). If you write a program that perform this call it will fire a system call and update the MAC address. Yet, then you will be doing exactly the same what ip link set does.
Change MAC address of network interface on lower level
1,395,122,243,000
I used the uuid command from the uuid-1.6.2-8.fc17.x86_64 package to generate version 1 UUIDs. The man page said that the default is to use the real MAC address of the host, but when I decoded the generated UUID, it is using the local multicast address. uuid v 1 shows: 5fc2d464-e1f8-11e1-9c3d-ff8beec65651 Decoding with uuid -d 5fc2d464-e1f8-11e1-9c3d-ff8beec65651 shows: encode: STR: c7ee12de-e1f7-11e1-99f1-53d638ec6296 SIV: 265752520555487307909286258714002350742 decode: variant: DCE 1.1, ISO/IEC 11578:1996 version: 1 (time and node based) content: time: 2012-08-09 07:56:52.526563.0 UTC clock: 6641 (usually random) node: 53:d6:38:ec:62:96 (local multicast) How can I make it use my actual MAC address, and my time zone (Asia/Tehran, not UTC)?
The reason it's not using your actual MAC address is because the code is poorly written. The mac_address function in uuid_mac.c has this block of code: if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) return FALSE; sprintf(ifr.ifr_name, "eth0"); if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { close(s); return FALSE; } It's looking for the MAC address of the eth0 interface, and silently falling back to a randomly-generated local multicast address if it can't find it. If your network interface is called eth1 or wlan0 or anything else, it fails to find it. I would consider this a bug in the software. It should use the MAC address of the hardware interface corresponding to the current default route, and let the user specify an alternate interface if desired. I'd recommend reporting that upstream. Regarding timezone: the UUID doesn't store the timezone. The time information in the UUID is stored as UTC time, and so that's how uuid -d displays it. An enhancement to the uuid program might be to provide an option to display times according to the local timezone when decoding -- but either way, that info doesn't get stored inside the UUID itself.
UUID based on global MAC address
1,395,122,243,000
I have machine at the office which is shut off I was hoping to turn it on from home using wake on lan. Reading about this, I have realized that I need the MAC address of the machine. Is there a way to find the MAC address of the machine from my ssh connection history? I use an RSA key to connect to the machine.
No, ssh has nothing to do with MAC addresses. If you are using DHCP you can maybe look into the logs or configuration files to determine the mac address.
Is there a way to find the mac address of a remote machine I have connected to with ssh?
1,395,122,243,000
I have various small NUCs with attached on each one some of this USB3 LAN adapters (because the NUCs have only one Ethernet, so I added extra ones with USB3 adapters). You can see an image of the product here. All of a sudden, probably due to an unattended automatic upgrade, these devices started getting random MAC addresses. Before: Each USB3 attached device had an address in the form: 00:0E:C6:XX:XX:XX Each one was distinct and always the same (stable), surviving reboots. Now they have address like: eth1 - be:7d:ee:6a:26:ab eth2 - be:7d:ee:6a:26:ab eth3 - be:7d:ee:6a:26:ab eth4 - be:7d:ee:6a:26:ab eth5 - be:7d:ee:6a:26:ab all sharing the same randomly picked address. In short, troubles: Each time the machine reboots, this random MAC address changes. They all share the same random MAC address.  Previously each one had a different and clearly distinct one. The devices are identified in lsusb as:    ASIX Electronics Corp. AX88179 Gigabit Ethernet I have no idea what happened since latest automatic update, it's matter of the latest 2 days, 1h ago everything was working OK, after all these devices started to have this weird behaviour. Could it be a problematic update?  Could it be a new driver been released that randomizes the MAC address each time?  Could it be a feature from the Linux kernel or the distro or GRUB setting where USB LAN devices now get random MAC address each time?  But in this case, why all of them share the same?  They should be totally random.... I am seeking help and willing to do tests... Regarding the OS: Debian Version: 12.5 Linux 6.1.0-20-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.85-1 (2024-04-11) x86_64 GNU/Linux Workarounds suggested so far, including the final one always working thanks to @A.B: Use parrent attribute "serial" in UDEV configuration to assign lan interface another name instead of relying on the mac address Use usb path of an usb nic address in udev rules in order to assign an interface name instead of mac address How to reset status of a network adapter before assigning the name in a udev ruleset?
This 6.8 kernel commit, backported to 6.1.x: net: usb: ax88179_178a: avoid two consecutive device resets intended to avoid a double reset on the AX88179-based NIC had as side effect to get a random MAC address for the NIC. There's a fix in the works for future 6.9 kernel, already backported to kernel 6.1.85+ which acknowledges the previous issue (and is supposed to fix it). Here's the acknowledge part: net: usb: ax88179_178a: avoid the interface always configured as random address After the commit d2689b6a86b9 ("net: usb: ax88179_178a: avoid two consecutive device resets"), reset is not executed from bind operation and mac address is not read from the device registers or the devicetree at that moment. Since the check to configure if the assigned mac address is random or not for the interface, happens after the bind operation from usbnet_probe, the interface keeps configured as random address, although the address is correctly read and set during open operation (the only reset now). The problem is that Debian's kernel 6.1.0-20-amd64 already uses upstream kernel 6.1.85 which includes the fix. From OP's comment this doesn't appear to work correctly, since OP is using kernel 6.1.0-20-amd64. What is guaranteed to work is to revert to the previous state: before the patch backported to 6.1.x on 2024-02-05. It appears that currently that means reverting TWO patches: net: usb: ax88179_178a: avoid the interface always configured as random address net: usb: ax88179_178a: avoid two consecutive device resets to be guaranteed to get it working as before (and getting the double-reset behavior back which didn't appear to be a problem then). I could verify in the past weeks that reverting net: usb: ax88179_178a: avoid two consecutive device resets made it work, I didn't verify how the newer state (eg: kernel 6.1.85 or Debian 6.1.0-20-amd64) behaves. OP's Q/A suggests that maybe the 2nd patch intended to fix the behavior caused after the 1st patch is not enough and possibly yet-an-other-fix has to be provided. To summarize, possible options today: keep an older kernel, such as Debian's 6.1.0-18-amd64 available from https://snapshot.debian.org/ there: linux-image-6.1.0-18-amd64 patch a kernel between 6.1.77 and 6.1.84 by reverting the first patch mentioned in this answer and recompile (tested working) check if a kernel 6.1.85 or newer works for you as is. either it works (nothing more to do) or it doesn't (OP's case) revert at least the first patch and recompile: net: usb: ax88179_178a: avoid the interface always configured as random address (optional, can be kept rather then be reverted) net: usb: ax88179_178a: avoid two consecutive device resets: (reverting this one is needed) or wait yet-a-future patch fixing this: UPDATE: this commit from 2024-04-18: net: usb: ax88179_178a: avoid writing the mac address before first reading fixes it (I tested it on a 6.8.x kernel). It should probably be included in next 6.1.x upstream kernel 6.1.88, and will be picked sooner or later by Debian. Added bonus: the reset appears to be made back at probe time and no more on interface UP. So the delay for transitions between down and up is now faster.
Debian 12 – All of a sudden my USB3 LAN adapter gets assigned random MAC address at each reboot
1,395,122,243,000
I only have the BSSID of the specific target device I want to connect to. How can I determine the actual Wi-Fi network name that the device is connected to? I'm using kali linux, and I used crunch 8 14 | aircrack-ng -a2 -b [target device BSSID] -w [file saved using airodump-ng].
To get the Wi-Fi (SSID) to a specific BSSID, you can use the wash command. wash is a utility provided by the reaver package. Install the reaver package: apt-get install reaver Use the following command to run wash and scan for nearby access points, replace [INTERFACE] with the name of your wireless network interface: wash -i [INTERFACE] wash will display a list of access points along with their BSSID. Source: Wash Description reaver | wash Usage Example How to use the wash command to find WPS enabled routers with Backtrack 5 or Kali Linux
What is the command to get the wifi name of a BSSID device in Kali Linux?
1,395,122,243,000
You probably know that MAC address can be generated, for instance, in the following way: macaddr=$(dd if=/dev/random bs=1024 count=1 2>/dev/null|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/') echo $macaddr But this method can result in MAC address that looks like this one: 07:d4:51:9f:50:6c . You simply can't use the address . If you tried, you would get this error: # ip link set dev wlan0 address $macaddr RTNETLINK answers: Cannot assign requested address So the line above should be rewritten. And the question is how it should look like so the MAC address always was valid?
extract the first byte (e.g. 07 from your example) bitwise AND it with decimal 254 (11111110 - all bits except zeroth bit set) bitwise OR it with decimal 2 (00000010 - only 1st bit set) combine the first byte back with the last five bytes e.g. #! /bin/sh mac='07:d4:51:9f:50:6c' lastfive=$( echo "$mac" | cut -d: -f 2-6 ) firstbyte=$( echo "$mac" | cut -d: -f 1 ) # make sure bit 0 (broadcast) of $firstbyte is not set, # and bit 1 (local) is set. # i.e. via bitwise AND with 254 and bitwise OR with 2. firstbyte=$( printf '%02x' $(( 0x$firstbyte & 254 | 2)) ) mac="$firstbyte:$lastfive" echo "$mac" Output: 06:d4:51:9f:50:6c 07 hex is 00000111 binary. bitwise AND-ing it with 254 (11111110 binary) results in 00000110 binary (6 decimal). bitwise OR-ing it with 2 (00000010 binary) results in no change because bit 1 is already set. Final result is 06 hex.
How go generate a valid and random MAC address?
1,395,122,243,000
Is it possible to generate a unique ID that wouldn't change over time unless there is hardware changes. The hardware must be generated with a c program. That also would be great if it were robust to spoofing, like MAC address or hard disk serial number spoofing. But that is not an absolute requirement. I need such an ID in order to collect software datas for statistics from lot of different computers. I've already read a lot of similar posts, like this one : generate consistent machine unique ID; but they don't suit my needs. I need this program to run as normal user, so I can't use command like "dmidecode" and such. Even if I have no other solutions than to use MAC addresses, I don't want the UUID to change if the user switch from Wifi to ethernet, so just take the first mac address can be problematic. On top of that the UUID has to remain identical even if they install a VMware or VPN. So taking all the mac addresses is neither an option because those previous tools generate more network interfaces and so more mac addresses, thus changing the UUID. I also want it to work on virtual machine, the guest uuid generated should be different than the host one. I don't even know if there is such a solution for this problem. But what I thought would be to only take the mac addresses of all physical existing hardware interface by reading in sys/class/net/*/addresses. Then appending all mac addresses and hashing them with sha1 to generate the UUID. But how can I filter the repertories to only select inchanging one. And can I be sure that their ordrer won't be swapped, thus changing the appended string and so the UUID. Otherwise, can I retrieve the hard disk serial number without root privilegies and third party tools? (If I can find the source for third party software it's okay) Any other solutions would also be very welcome. PS : It has to be compatible with any linux versions with kernel 2.6 or higher
Short answer From all my researches and attempts, I would say that it is not possible to make a program that would generate a unique ID respecting the following constraints. The ID must be the same every time if generated on the same computer. The ID must be different if generated on different computers. The program must run as user. The program must be compatible with any linux distribution with a 2.6 kernel version or higher The ID may be different if the computer is modified (eg : hardware replacement) The program shouldn't rely on third party tools that has to be installed on the computer Long answer Here I will present my attempt with the mac addresses. The goal here was to find a way to retrieve the addresses of all the physical network interfaces. As a normal user, I saw that the easiest way to find mac addresses would be to read the system files in the "/sys" directory. Those files are available since linux 2.6, so that's perfect. My research took me to those sets of rules : https://www.kernel.org/doc/Documentation/sysfs-rules.txt The use of the udev library as advised in those rules is not possible because it has to be externally added. So I dove into the source that can be found here : http://cgit.freedesktop.org/systemd/systemd/tree/src/libudev What I learned from this, is that to retrieve the mac addresses you should look for "sys/subsystem", if present then look for a "net" directory within it, and you'll find directories with each network interface. If there is no "subsystem" folder, you have to look in "sys/class", "sys/bus" and "sys/block" folders for the "net" directory. In fact, I always found them in "class", but the rules said that it should not be expected. Above I said that in the "net" folder, you'll find the network directories, that's not entirely true. On linux 2.6 (I used RHEL 4), it is directories and within you'll find, among others, the "address" file containing the mac address a symlink targeting a directory in "sys/devices". If on a higher linux version, it will directly be a symlink to a directory in "/sys/devices", in which you'll find the "address" file. (I tried on RHEL 6, Debian 7, Debian 8, Ubuntu 15 and Ubuntu 15 with kernel updated to linux 4.3) I never saw the "/sys/subsystem" directory even in the new linux version (4.3). New layout of sysfs ( >= linux 3) : To tell the physical interface from the virtual one, I wanted to look at the devpath of the device. The symlink that I have in "/sys/class/net" target to these directories : "/sys/devices/pci0000:00/0000:00:11.0/0000:02:01.0/net/eth0" "/sys/devices/virtual/net/eth1" The eth1 was a dummy virtual nic that I created following this topic : How can I create a virtual ethernet interface on a machine without a physical adapter? So you can see that the virtual one are in a "virtual" folder, so that would be the way to tell them apart. Old layout of sysfs (linux 2.6) : The virtual network interface doesn't have a "device" symlink in their directories. You will find "/sys/class/net/eth0/device -> /sys/devices...." But if there was a virtual eth1, there will be no such symlink in "/sys/class/net/eth1". So all in all, using "opendir", "readdir", "access('...',F_OK)", "fopen".. you could retrieve the mac addresses of only physical interfaces. Then just sort them, so that you are sure they will come in the same order, then append all in a buffer and use a SHA1 from openssl, do a little parsing to make it look like a UUID and you are good to go. But the thing is, I didn't want to rely on the fact that there will be a "virtual" folder anywhere in the devpath to a network device. It is never said in the rules, linked above, that this would always be the case. So the problem can't be answer this way. I hope that all my researches will help someone.
generate consistent machine unique ID in c programming
1,395,122,243,000
Question: What is the terminal command behind right clicking on the wireless icon (Ubuntu 15.04) and then unchecking "Enable Wi-Fi" the box? Why am I asking it? macchanger just work for me when I disable my wifi via GUI, call sudo macchanger -e wlan0 and enable the wifi via GUI again. When I try using the command lines below, although I get no error, at the end my MAC address remains the same: sudo ifconfig wlan0 down sudo macchanger -e wlan0 sudo ifconfig wlan0 up Same applies when I try with: sudo ip link set dev wlan0 down ...
If you're using NetworkManager (and you very likely are): nmcli radio wifi off. This is simply a command line interface equivalent of the widget. NetworkManager is a complicated beast. I'm not sure what the basic commands are that it's using.
Disabling wlan0 adapter
1,395,122,243,000
Does ifconfig show the MAC address of a network interface following ether? Does ether mean ethernet? How does it mean Mac address? virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:b1:aa:1f txqueuelen 1000 (Ethernet) RX packets 451 bytes 43572 (43.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 108 bytes 28182 (28.1 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlx8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.97 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 xx:xx:xx prefixlen 64 scopeid 0x20<link> ether 80:1f:02:b5:c3:89 txqueuelen 1000 (Ethernet) RX packets 697657 bytes 564556036 (564.5 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 374913 bytes 60332457 (60.3 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
As explained in the ifconfig manpage, in the section on setting options, Set the hardware address of this interface, if the device driver supports this operation. The keyword must be followed by the name of the hardware class and the printable ASCII equivalent of the hardware address. Hardware classes currently supported include ether (Ethernet), ax25 (AMPR AX.25), ARCnet and netrom (AMPR NET/ROM). This also explains the output, i.e. ifconfig shows the current hardware address of the interface, with its hardware class. For Ethernet interfaces, the class is ether and the hardware address is the MAC address.
Does `ifconfig` show the MAC address of a network interface following `ether`?
1,454,607,563,000
I'm connecting a linux machine using a nowadays popular Huawei Brovi E3372-325 LTE USB Stick to the internet. The special requirement is that incoming ssh/ping/NTP/... connections must reach my linux OS. The state is, that using usb_modeswitch -X and the option driver I can bring up the 3 ttyUSB interfaces, and connect successfully using wvdial. But for some reason, ifconfig does not list a HW/MAC address for ppp0 interface, and devices on the same APN network can't ping the my IP address. I don't think the reason is blockage by the ISP, because my other devices are ping-able on the network. Output of ip addr 19: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 3 link/ppp inet 10.250.0.112 peer 10.64.64.64/24 scope global ppp0 valid_lft forever preferred_lft forever If I'm not mistake, I don't use RNDIS right now. Am I right, that in general the popular RNDIS protocol does not suit my use case, because that creates an additional local network, making it trickier to forward incoming connections to the OS? Pinging might work from outside because that's answered by the USB modem itself, but incoming ssh would fail. What might be the reason, that ppp0 does not have a MAC address? How it's even possible? Should I assign one? Is it probably the reason that other devices can't ping it's IP? How to solve this situation?
If I'm not mistake, I don't use RNDIS right now. RNDIS is a Windows-specific network interface driver API. Um, that as nothing to do with what you're doing, right? What might be the reason, that ppp0 does not have a MAC address? How it's even possible? a MAC address is an Ethernet concept; and PPP is not ethernet :) PPP's frame do contain an Address – but it's just a single byte long, and always set to 0xFF, PPP being a point-to-point protocol, where you don't need more addresses (you know who you're talking to – the other end). I don't think the reason is blockage by the ISP, because my other devices are ping-able on the network. Good debugging. Note, however, that mobile network operators (MNOs) routinely employ carrier-grade NAT to hide a lot of users behind one public IPv4 address – there's even theoretically, ignoring anything else but humans with phones – only 2³² possible IP addresses (ignoring any "special" addresses), and roughly as many phones as there are humans, so there's only IPv4 addresses for around half of the phones. The message here is that if you want your mobile device to be world-reachable, there's going to be some extra infrastructure involved (like a VPN server), or you need to use IPv6. I'd recommend going for IPv6 – due to market forces, for most MNOs it's cheaper to have IPv6 traffic to and from the internet, so they might prioritize that. Anyway, your question is why it doesn't work for you – here's the thing: This is carrier-grade NAT (your IPv4 address on that interface is a private one!), there's neither a guarantee nor too much sense in guaranteeing that different subscribers can contact each other directly. It's cool that it works for you on your other devices, though. What's a bit worrying is that you're only assigned a single IPv4 address, and not an IPv6 address (or a whole IPv6 subnet). That might mean that your Linux machine's pppd isn't configured to accept IPv6, or some other misconfiguration. But more realistically: PPP is an … old protocol that's got nothing to do with how mobile network infrastructure operates, at all. 2.5G/GPRS/EDGE, 3G/UMTS, 4G/LTE, 5G… etc are packet networks – you get an interface that transports IP packets, directly; you don't get a serial line over which you need to talk PPP to establish a packet tunnel. So, what must be happening is that your USB modem connects to the mobile network, gets an IP address, and puts the IP packets it gets through a PPP tunnel, which it seems to then put over an emulated serial link to your computer? That's an interesting way to do it, to say the least – could as well just have been a USB network card, and worked out of the box. In fact, that's how USB tethering on my phone works, and I had built-in modem cards for my laptops in the past, which did the same. Maybe your USB modem has different modes of operating, and one that looks like a 1990's dial-up modem that emulates connecting to an Internet Service Provider that offers PPP, and a different mode where it's just an IP router? If that's the case, use the latter mode, and set it to forward packets to your computer. So, either way, your modem is involved in mangling IP packets; so quite likely that's where your incoming packets get lost. But, maybe your other devices are also using the same APN nominally, but if they're using a different way of connecting to the mobile network, their packets go a different route in the core network, and don't end up in the same private network as your modem; there's much that could differ here, that you have zero visibility of. Generally, your MNO doesn't operate an internal network for you (unless you pay them to – for example using a special M2M subscription), but an internet access; communicate through the internet, if you can't communicate locally. For that you need a global IP address that you can connect to. If you asked me, if you need to be mutually communicating: Use IPv6. That's your best chance to actually get a global address. Fall back to IPv4 only if you positively must. Get some server that has a static public address. Your user equipment gets assigned a new IP address at will of your MNO. Establish a VPN connection to that public address from each of your devices – wireguard is an excellent, relatively low-power method for that. This might already solve all your problems. if you want to be Smart (with a capital S) about latencies, you can add additional direct network paths between different devices as soon as they detect they can mutually directly communicate – which requires some software running at the endpoints, delivering address information about the different network interfaces offered by your devices, and a daemon to make sense of these.
USB LTE modem without MAC address?
1,454,607,563,000
I have Comcast cable <====> modem <===> router <===> freebsd server My freebsd server is connected to wireless router via a network cable. What I want to do is, to have a static ip for the server. How can I do it?
You can set static IP address in FreeBSD in /etc/rc.conf file. First you need to know what is name of your network interface that you want to configure. Use ifconfig to list all network interfaces, when you find it add following line to /etc/rc.conf: ifconfig_INTERFACE_NAME="inet IP_ADDRESS netmask NETMASK" for example: ifconfig_dc0="inet 192.168.0.2 netmask 255.255.255.0"
static ip to a freebsd server
1,454,607,563,000
I use this command to get the name of my network interfaces and their mac address ip -o link | awk '$2 != "lo:" {print $2, $(NF-2)}' | sed 's_: _ _' out: enp2s0 XX:XX:XX:XX:XX:XX wlp1s0 YY:YY:YY:YY:YY and this one to get the IP: ip addr show $lan | grep 'inet ' | cut -f2 | awk '{ print $2}' out: 127.0.0.1/8 192.168.1.23/24 or this one: ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' or another: ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1 out: 192.168.1.23 What command can I use to know (the order is not relevant): interface name | IPv4 address | MAC address example: enp2s0 192.168.1.23 XX:XX:XX:XX:XX:XX in a single line, but only from active interfaces (except lo) (for ubuntu 20.04)? I have tried this solution but it did not work for me
In bash this works: paste <(ip -o -br link) <(ip -o -br addr) | awk '$2=="UP" {print $1,$7,$3}' but it relies on the ip output being in the same order for link and addr. To be sure, you could use join with sort instead: join <(ip -o -br link | sort) <(ip -o -br addr | sort) | awk '$2=="UP" {print $1,$6,$3}' In sh command substitution isn't available, so it couldn't be quite as concise as this.
how do i get interface name, ip and mac from active interface only (except lo)
1,454,607,563,000
I've been making a BASh script that changes your MAC Address to that of any manufacturer of your choice from a list. At the last part of the script that is run, it stops before finishing. Here is the code for that part: function spoofUseMAC() { echo read -p "[*] $($stopAllFX; $bgBlack; $white)Enter the number code for manufacturer: >>> " num echo "[-] Generating MAC Address" num=$( expr $num - 1 ) declare -a array while read -r; do array+=( "$REPLY" ) done < addr.txt end=$( for i in {1..6} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' ) macAddress=${array[$num]}$end echo "[-] MAC Address generated !" echo "[-] Using address: $macAddress" $skyBlue; $bold; echo ifconfig $white read -p "[*] $($stopAllFX; $bgBlack; $white)Select an interface: >>> " iface $yellow; echo "[-] $iface selected !" $white; echo "[-] Disabling $iface ..." ifconfig $iface down ifconfig '$iface' hw ether '$macAddress' echo "[-] MAC Address spoofed !" sleep 1 echo "[-] Enabling $iface ..." ifconfig '$iface' up echo "[-] $iface enabled !" echo "[-] Using address: $macAddress" exit } function spoofSearchAgainOrNot() { $bold; $white; echo echo "[*] $($stopAllFX; $bgBlack; $white)Please select an option from the list below:" $yellow; $bold; echo " [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Search again" $yellow; $bold; echo " [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Use one of these" read -p ">>> " searchAgainOrNot if [[ "$searchAgainOrNot" == "0" ]]; then spoofSearch elif [[ "$searchAgainOrNot" == "1" ]]; then spoofUseMAC else spoofSearchAgainOrNot fi } # Spoof, search option selected function spoofSearch() { $bold; echo read -p "[*] $($stopAllFX; $bgBlack; $white)Search for a manufacturer: >>> " search $blue; awk -F '#' '{printf("%10d %s\n", NR, ":" $1 )}' /usr/bin/oui.txt | grep -i $search spoofSearchAgainOrNot } # Spoof function spoof() { echo; $white echo "[*] $($stopAllFX; $bgBlack; $white)Please select an option from the list below:" $yellow; $bold; echo " [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Search for a manufacturer" $yellow; $bold; echo " [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Browse for a manufacturer through $($bold)long $($stopAllFX; $bgBlack; $white)list" read -p ">>> " searchOrBrowse if [[ $searchOrBrowse == "0" ]]; then spoofSearch elif [[ $searchOrBrowse == "1" ]]; then spoofBrowse else spoof fi } Why can't I use the internet (git clone says could not resolve hostname: github.com) after running this script? And why is it not finishing? EDIT: This is supposed to work on MacOS and Linux. On MacOS, there is no ip route command, but in Linux, ip route results in: 192.168.0.0/24 dev wlp1s0 proto kernel scope link src 192.168.0.18 192.168.0.0/24 dev wlp1s0 proto kernel scope link src 192.168.0.18 metric 600
I found the problem: one of the $ifaces had quotes around it when it shouldn't have.
Cannot connect to internet after changing MAC Address
1,454,607,563,000
I'm using dnsmasq as a DNS server only (no dhcp), mapping Lan's hostnames to relative ip using /etc/hosts, but in the same Lan there's some ip assigned dynamically by a router (and I'd like to keep so, I don't want to use dnsmasq'd dhcp but I want to keep the ip dynamic). Any way to map a MAC-address with a hostname so the DNS can respond correctly for a dynamically assigned ip? I seen the documentation of dnsmasq and played around with /etc/ethers and dhcp-host= but the former is only for MAC->ip (not hostname) and the latter only if dhcp is enabled, so far found nothing else.
Solved, see poor-mans-device-discovery-dns new link Use dnsmasq's option addn-hosts=/etc/dyn.hosts to read an additional hosts file, which is generated periodically using the command arp-scan (and cron or whatever).
dnsmasq as dns only, map mac-address to hostname for dynamic ip
1,454,607,563,000
I have several devices connected to my wifi, and I need to assign them a static ip address, but NetworkManager gives them sometimes different ip addresses. I tried adding a file in /etc/network/if-up.d/ with the command arp -i wlp6s0 -s 10.42.0.2 e8:b4:c8:2a:5c:45 but didn't work, then I tried disabling NetworkManager dnsmasq with no results. The device still has the ip 10.42.0.37. Any thoughts?
The thing with Network Manager is that it calls dnsmasq for configuring dns and dhcp when the wifi acts as an Access Point. You can overwrite that configuration by adding files with the .conf extension into the directory /etc/NetworkManager/dnsmasq-shared.d/ And thats all. In my case I added a few lines configuring dhcp to asssign static ip by mac address, this is the content of the file: static-ips.conf dhcp-host=e8:b4:c8:2a:5a:48,10.42.0.25 (....)
How to assign static ip to devices connecting over wifi using Network Manager?
1,454,607,563,000
How do I find my MAC address on RHEL 7.3? When I ran ifconfig -a | grep HWaddr, nothing showed. It's an EC2 instance, if that means any deviation from the norm.
The command ip link shows the MAC address on all interfaces.
How to find MAC address on RHEL 7.3?
1,454,607,563,000
Running Ubuntu 22.04.3 LTS on top of WSL2 Output of ifconfig: eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1492 inet 172.28.193.11 netmask 255.255.240.0 broadcast 172.28.207.255 inet6 fe80::215:5dff:fe3e:7ffa prefixlen 64 scopeid 0x20<link> ether 00:15:5d:3e:7f:fa txqueuelen 1000 (Ethernet) RX packets 1402 bytes 590609 (590.6 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 163 bytes 52446 (52.4 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (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 Output of ipconfig /all from PowerShell (pardon my machine's French): Configuration IP de Windows Nom de l’hôte . . . . . . . . . . : Zenbook-OZ Suffixe DNS principal . . . . . . : Type de noeud. . . . . . . . . . : Hybride Routage IP activé . . . . . . . . : Non Proxy WINS activé . . . . . . . . : Non Liste de recherche du suffixe DNS.: Speedport_W_724V_01011603_07_008 Carte réseau sans fil Connexion au réseau local* 1 : Statut du média. . . . . . . . . . . . : Média déconnecté Suffixe DNS propre à la connexion. . . : Description. . . . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter Adresse physique . . . . . . . . . . . : 3E-55-76-BE-66-95 DHCP activé. . . . . . . . . . . . . . : Oui Configuration automatique activée. . . : Oui Carte réseau sans fil Connexion au réseau local* 2 : Statut du média. . . . . . . . . . . . : Média déconnecté Suffixe DNS propre à la connexion. . . : Description. . . . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #2 Adresse physique . . . . . . . . . . . : 3E-55-76-BE-76-85 DHCP activé. . . . . . . . . . . . . . : Oui Configuration automatique activée. . . : Oui Carte réseau sans fil Wi-Fi : Suffixe DNS propre à la connexion. . . : Speedport_W_724V_01011603_07_008 Description. . . . . . . . . . . . . . : MediaTek Wi-Fi 6E MT7922 (RZ616) 160MHz Wireless LAN Card Adresse physique . . . . . . . . . . . : 3C-55-76-BE-46-B5 DHCP activé. . . . . . . . . . . . . . : Oui Configuration automatique activée. . . : Oui Adresse IPv6. . . . . . . . . . . . . .: 2003:c5:c715:bad9:aa0e:5e09:f399:6903(préféré) Adresse IPv6 temporaire . . . . . . . .: 2003:c5:c715:bad9:fc98:b63c:31e6:1374(préféré) Adresse IPv6. . . . . . . . . . . . . .: 2003:c5:c715:badb:904b:d90b:7543:f858(déprécié) Adresse IPv6 de liaison locale. . . . .: fe80::f215:b016:e094:6711%13(préféré) Adresse IPv4. . . . . . . . . . . . . .: 192.168.2.106(préféré) Masque de sous-réseau. . . . . . . . . : 255.255.255.0 Bail obtenu. . . . . . . . . . . . . . : mercredi 13 mars 2024 01:52:12 Bail expirant. . . . . . . . . . . . . : jeudi 4 avril 2024 00:38:51 Passerelle par défaut. . . . . . . . . : fe80::1%13 192.168.2.1 Serveur DHCP . . . . . . . . . . . . . : 192.168.2.1 IAID DHCPv6 . . . . . . . . . . . : 121394550 DUID de client DHCPv6. . . . . . . . : 00-01-00-01-2C-2A-D6-E9-00-4C-E0-86-43-54 Serveurs DNS. . . . . . . . . . . . . : fe80::1%13 192.168.2.1 NetBIOS sur Tcpip. . . . . . . . . . . : Activé Carte Ethernet Connexion réseau Bluetooth : Statut du média. . . . . . . . . . . . : Média déconnecté Suffixe DNS propre à la connexion. . . : Description. . . . . . . . . . . . . . : Bluetooth Device (Personal Area Network) Adresse physique . . . . . . . . . . . : 3C-55-76-BE-46-B6 DHCP activé. . . . . . . . . . . . . . : Oui Configuration automatique activée. . . : Oui Carte Ethernet vEthernet (WSL (Hyper-V firewall)) : Suffixe DNS propre à la connexion. . . : Description. . . . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter Adresse physique . . . . . . . . . . . : 00-15-5D-AE-85-70 DHCP activé. . . . . . . . . . . . . . : Non Configuration automatique activée. . . : Oui Adresse IPv6 de liaison locale. . . . .: fe80::5516:60d0:65b2:eb67%35(préféré) Adresse IPv4. . . . . . . . . . . . . .: 172.28.192.1(préféré) Masque de sous-réseau. . . . . . . . . : 255.255.240.0 Passerelle par défaut. . . . . . . . . : IAID DHCPv6 . . . . . . . . . . . : 587208029 DUID de client DHCPv6. . . . . . . . : 00-01-00-01-2C-2A-D6-E9-00-4C-E0-86-43-54 NetBIOS sur Tcpip. . . . . . . . . . . : Activé My question: I don't understand where the IP address 172.28.193.11 (assigned to eth0 in the output ifconfig) comes from. The MAC address 00:15:5d:3e:7f:fa associated to eth0 in ifconfig does not appear anywhere in the output of ipconfig /all on PowerShell. To what network interface does the MAC address 00:15:5d:3e:7f:fa correspond?
A few notes, starting with the suggestion to use the ip command and its subcommands. This replaces the deprecated ifconfig command. I'll use ip commands for any examples in this answer. As mentioned in the other answer, WSL2 by default Footnote uses a virtual network interface. As for "where the ... address ... comes from", there's a Hyper-V virtual switch that interfaces between WSL and your computer. You can see that virtual switch if you have both Windows Professional (or higher) and the Hyper-V Manager feature installed, by selecting the Virtual Switch Manager... action in the right-hand pane. However, I generally recommend you not make any modifications to it unless you are really certain you have the expertise. That virtual switch also handed out the IP address you see for the WSL (Hyper-V firewall) interface in your ifconfig output. In WSL, run ip route to show that the traffic is routing to the IP address of the WSL switch in Windows. In your output, that was 172.28.192.1, so you should see: $ ip route default via 172.28.192.1 dev eth0 proto kernel Footnote: Mirrored Mode The (WSL (Hyper-V firewall)) in your ipconfig output in Windows tells me that you are running a fairly recent release of WSL2 that includes a new networking mode. As mentioned above, the default networking mode in WSL2 is NAT. Up until fairly recently (September 2023), this was the only networking mode available to WSL2. However, release 2.0.0 of WSL2 brought several new "experimental" features, including "Mirrored" networking mode, where Windows network interfaces are mirrored into WSL2 instead of being NAT'd. That feature has been promoted, and is no longer experimental in the latest production WSL2 release. If you were to have Mirrored mode enabled in your .wslconfig, then the IP addresses and interfaces you see with ifconfig/ip addr would generally match up with what you see in the Windows ipconfig /all command.
Machine MAC address with Ubuntu on top of WSL2
1,454,607,563,000
I'm trying to know a way to show only MAC address from every NIC I have on any running virtual machine: So far I have this: ipcopv2 ----------------------------------------------- Groups: /Infraestructura State: powered off (since 2018-03-16T13:30:56.389000000) NIC 1: MAC: 080027D40320, Attachment: Bridged Interface 'eth1.15', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 2: MAC: 080027660656, Attachment: Bridged Interface 'eth1', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 3: MAC: 0800270D3D9E, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none Capture screens: 0 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> I want to have this: ipcopv2 ----------------------------------------------- Groups: /Infraestructura State: powered off (since 2018-03-16T13:30:56.389000000) NIC 1: MAC: 080027D40320, Attachment: Bridged Interface 'eth1.15', Cable connected: on NIC 2: MAC: 080027660656, Attachment: Bridged Interface 'eth1', Cable connected: on NIC 3: MAC: 0800270D3D9E, Attachment: Bridged Interface 'eth0', Cable connected: on Capture screens: 0 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> How to accomplish this? I want to understand how to read the info and only show that part using bash.
This seems to do the trick: $ ip link | awk '/link/ { print $2 }' 00:00:00:00:00:00 00:20:78:1c:xx:yy 00:1d:92:67:xx:yy
how to show only mac address on virtualbox
1,454,607,563,000
I am new to Linux. Today, I installed Linux Mint (17.2) and tried to connect to the internet via a broadband connection. My Internet Service Provider (ISP) provided me with a fixed MAC address that they expect me to use as computer hardware identification. Thus, I need to change my current default MAC address. After doing some research, I've found out that there is a macchanger package that I could use. However, this requires a working internet connection to download, so I couldn't do that. Alternatively, I've tried the installed Network Connections application to edit the MAC address of my network adapter, but after changing it, it got set back to default. I've also tried the following command: sudo ifconfig hw enter <MAC Address> but the MAC address remains default. So, what other options do I have to resolve my problem?
Problem You bought a new computer to replace your old one. You brought it home and followed the quickstart guide, and it's all setup. You then disconnected your ISP's equipment, or at least turned off the power to disconnect your connection. You then plugged everything in exactly the way it was before, and turned on your new shiny PC/Laptop etc. only to find you cant connect to the Internet. Reasoning Some ISP's, including the OP's limit their network connections by monitoring your computer's MAC Address in what's called a Bridge Table. The Bridge Table stores the MAC Address of every user connected to the ISP. When your ISP connected you, i.e., you started paying for service, you were given a bridged/bridging modem, to allow for transparent bridging. See Figure 1 (modem type and brand are irrelevant, I just needed a picture): In Transparent Bridging your ISP can only see the MAC Address of the First Device connected past the modem. The modem's only job is to make sure you are connected properly and achieve Sync. In Figure 1's case the first device is the Desktop PC, therefore that Desktop PC's Ethernet Card MAC Address has been stored by your ISP. If you swap out PC's the MAC Address from your Old PC (stored in the Bridging Table) no longer matches the MAC Address of your new PC. Note this also happens when you add a router, as in Figure 2. The MAC Address of the router no longer matches the MAC Address of the PC stored in the Bridging Table. In both cases, since the addresses don't match, the transparent bridge is broken, which is why the OP and others can't connect. Fixes Now that we understand why the bridge broke, we have 2 major ways to fix the problem. MAC Address Cloning - This is what the OP is trying to accomplish. The first PC or device that was connected to his service contained a network card with the MAC ID of 00:E0:4C:1A:6B:3F. Using Coffer's MAC Vendor Lookup, we can determine at least who made the original Network Card, in this case, Realtek. Assuming we no longer have access to the device, we must Clone its address as seen below for Windows: and here for NetworkManager Based Linuxes: Taken from: How (and Why) to Change Your MAC Address on Windows, Linux, and Mac Personally, I hate Fix Number 1, but it's the most common. It's common because some ISP support people are taught that it's normal, and the others are just lazy. As such, I consider the fix below the "more proper" fix." Call your ISP support line, and kindly wait for a representative. Tell him or her that you bought a new PC/Laptop etc, and that you only need the Bridging Table cleared, because you know that the old MAC Address there won't match. Don't lose your temper because the representative will either respond: that he can do that. When he asks if he can do anything else, say No, and offer to rate his call, as he responded correctly. with no response. This is bad because he will try to lead you to Fix Number 1, after following the steps lined out in the helpdesk documents. If he does this ask for his supervisor, or another representative until you get one that responds favorably.
Internet connectivity issues due to wrong MAC address (using Linux Mint 17.2)
1,454,607,563,000
I'm using SuSE 12.2 with custom kernel 4.4.21 (minor changes related to real time environment). Is it really necessary to down/up the interface during the MAC address change? What I observed is that it is not really necessary (the change succeeds on enabled interface, without a need to turn it off). However - most of the examples in the internet suggests to down interface, then change the MAC address, and after that up it again, e.g. howtogeek.com. Is this procedure described somewhere in documentation?
Changing the MAC address of an interface is hardware and driver dependent. When the interface is up, more actions must be done to update the interface's state while still running. Some drivers just don't support it, either yet, or because the interface's hardware can't permit such feature. The modern method to distinguish this capability on an interface is the priv_flag IFF_LIVE_ADDR_CHANGE which appeared in kernel 3.6. I can't tell if before there was an other mechanism for this and if thus it was possible before. One can just run an older kernel and check what's working. The patch introducing this is: 2012-06-30 net: introduce new priv_flag indicating iface capable of change mac when running Introduce IFF_LIVE_ADDR_CHANGE priv_flag and use it to disable netif_running() check in eth_mac_addr() As one can expect, this feature was added right after to a few simple virtual devices, like the dummy interface: 2012-06-30 virtio_net: use IFF_LIVE_ADDR_CHANGE priv_flag 2012-06-30 team: use IFF_LIVE_ADDR_CHANGE priv_flag 2012-06-30 dummy: use IFF_LIVE_ADDR_CHANGE priv_flag Some examples of further additions of this feature over time, per driver: 2014-06-10 gre: allow changing mac address when device is up 2018-07-03 r8169: fix mac address change Here's a very old 3Com Tornado network card not allowing this, that I still have available: # uname -r 4.19.0-0.bpo.6-686-pae # ethtool -i eth1|grep driver driver: 3c59x # lspci|grep 3Com 02:0c.0 Ethernet controller: 3Com Corporation 3c905C-TX/TX-M [Tornado] (rev 78) # ip link set dev eth1 address 02:00:00:00:00:01 RTNETLINK answers: Device or resource busy # ip link set dev eth1 down # ip link set dev eth1 address 02:00:00:00:00:01 # ip link set dev eth1 up # ip link show dev eth1 2: eth1: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 02:00:00:00:00:01 brd ff:ff:ff:ff:ff:ff So the suggestion of having the interface down to change the MAC address still applies here.
Is it necessary to down/up interface during MAC address change?
1,454,607,563,000
From https://networkengineering.stackexchange.com/questions/57935/is-a-network-interface-supposed-to-have-no-more-than-one-mac-address/57937?noredirect=1#comment100988_57937 A network interface in a MAC-based network always requires a MAC address, virtual or physical. However, there are networks that are not MAC-based. Doesifconfig show lo as a virtual network interface? ifconfig doesn't show its MAC address, does it mean lo has no MAC address, and the network of loopback IP addresses is not MAC-based? Thanks. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 2403613 bytes 138542051 (138.5 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2403613 bytes 138542051 (138.5 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Since the lo interface is not associated with a hardware network interface (it's a virtual loopback interface), it does not have an Ethernet hardware address (MAC address). Communication though the loopback interface is not MAC-based. No routing needs to take place to send packets between NICs.
Does `lo` have no MAC address?
1,454,607,563,000
When I create ad hoc wifi network with shared Ethernet connection to router, does the router register only the ad hoc host MAC address or all MACs of devices connected to router via the ad hoc network? I assume only MAC of ad hoc host, but I'm not sure. For example, I connect from laptop1 to laptop2 through ad hoc wifi, then connect to router through laptop2 shared Ethernet connection; does the router register MAC of laptop1 or laptop2?
It depends. If laptop1 is doing it as a bridge, it will appear to the router as if there is a switch with two computers. The router will have laptop2's MAC address. Laptop1 might do it using NAT. That way, the router won't know about laptop2; laptop1 will take care of everything.
MAC address through ad hoc wifi
1,454,607,563,000
I installed CentOS 6.X with VMWare Fusion. It looks like the mac address and nic names changes randomly. eth8 and eth9, totally weird. Anyone know why? P.S VMWare pops a dialog asks me if I moved or copied the VM, although I never did anything to the Virtual Machine. And each time I choose I moved it, maybe it's relevant to the problem? P.P.S I also have other Linux VMs, e.g Ubuntu which never had such problems, Hmm.
According to vmware-support You need to assign the MAC adress manually to avoid changes in the MAC automatically evrytime you moved it. If you want to guarantee that the same MAC address is assigned to a given virtual machine every time, even if the virtual machine is moved, or if you want to guarantee a unique MAC address for each virtual machine within a networked environment, you can assign the address manually instead of allowing VMware Workstation to assign it automatically. To assign the same, unique MAC address to any virtual machine manually, use a text editor to remove three lines from the configuration file and add one line. The configuration file has a.vmx extension at the end of the filename. On a Linux host, a virtual machine created with an earlier VMware product may have a configuration file with a .cfg extension. As it's described: Remove the three lines that begin with the following from the configuration file: ethernet[n].generatedAddress ethernet[n].addressType ethernet[n].generatedAddressOffset In these options, [n] is the number of the virtual Ethernet adapter — for example ethernet0. Add the following line to the configuration file: ethernet[n].address = 00:50:56:XX:YY:ZZ Or you can edit the file like the following example: ethernet[n].addressType = "static" ethernet[n].checkMACAddress = "false" ethernet[n].address = "00:50:56:XX:YY:ZZ"
CentOS 6 in VMWare fusion: Unexpected MAC address change
1,454,607,563,000
I want to match all data from ens19 with the mac address 88:7e:25:d3:90:0b use table 147. My idea is to mark the data from 88:7e:25:d3:90:0b and give it a fwmark 14. Then use ip rule to the specified route table So I make this command nft add rule filter input iif ens19 ether saddr = 88:7e:25:d3:90:0b mark set 147 Error: syntax error, unexpected '=' add rule filter input iif ens19 ether saddr = 88:7e:25:d3:90:0b mark set 147 What is the correct way to do this command? Thanks
According to the documentation, the syntax you want is: nft add rule filter input iif ens19 ether saddr 88:7e:25:d3:90:0b mark set 147
maching source MAC address in nftables
1,464,617,834,000
In my script I need to randomly generate MAC addresses. The code below is from a larger script extracted, that's why the MAC address calculation is in a separate function. This works fine with the code below. Although when I execute the script it slows heavily down after a number of generated addresses. How can I improve the speed of generating valid MAC addresses? #!/bin/bash devicesCSVMacAddress="55:2d:fa:07" # <- fake MAC address prefix devicesCSVFile='' function mac_address() { line='' # **************** # This line below when I calculate a random mac address ending seems to be slow line+=$devicesCSVMacAddress$(od -txC -An -N2 /dev/random|tr \ :) # **************** devicesCSVFile+=$line'\n' date } for (( i=0; i<100; i++ )) do mac_address echo $i done echo -e $devicesCSVFile > devices.csv I used the od tool like it described in this answer: How to generate a valid random MAC Address with bash shell.
Use /dev/urandom! There is almost no good reason to use /dev/random instead of /dev/urandom -- see Myths about urandom or When to use /dev/random vs /dev/urandom -- and certainly not when you are going to publish the generated numbers all over the place. /dev/random consumes entropy, blocks and waits if not enough of it is available. /dev/urandom never blocks.
How to improve performance in generating MAC addresses with od?
1,464,617,834,000
I have a default gateway with IP address 192.168.1.1 and MAC address 5c:77:76:6e:0d:7b. It is my only wi fi modem router from which I receive internet. But in input nftables logs I saw another one router with the same IP address and different MAC address 5c:77:77:6e:0d:7b. This unknown router sends pages which I didn't open (spam). I tried two ways to solve this problem: Set up static arp cache. Now my arp cache looks like this: arp -a mw40.home (192.168.1.1) at 5c:77:76:6e:0d:7b [ether] PERM on wlo1 Drop packets from illegal router in etc/ nftables.conf: ether saddr 5c:77:77:6e:0d:7b counter drop; But after the second step, I lost my internet connection. My questions: What is happening in this piece of log (below)? How are the two routers communicating with each other? How I can remove from my network the illegal router with MAC address 5c:77:77:6e:0d:7b? Sep  1 15:16:03 flower kernel: [  133.359821] New Input packets: IN=wlo1 OUT= MAC=b8:81:98:cb:ef:a8:5c:77:77:6e:0d:7b:08:00 SRC=85.159.224.52 DST=192.168.1.2 LEN=76 TOS=0x18 PREC=0x60 TTL=49 ID=4873 DF PROTO=UDP SPT=123 DPT=47244 LEN=56 Sep  1 15:16:11 flower kernel: [  141.053122] New Input packets: IN=wlo1 OUT= MAC=b8:81:98:cb:ef:a8:5c:77:77:6e:0d:7b:08:00 SRC=192.168.1.1 DST=192.168.1.2 LEN=185 TOS=0x00 PREC=0x00 TTL=64 ID=32498 DF PROTO=UDP SPT=53 DPT=56881 LEN=165 Sep  1 15:16:12 flower kernel: [  141.660330] New Input packets: IN=wlo1 OUT= MAC=b8:81:98:cb:ef:a8:5c:77:77:6e:0d:7b:08:00 SRC=192.168.1.1 DST=192.168.1.2 LEN=111 TOS=0x00 PREC=0x00 TTL=64 ID=32521 DF PROTO=UDP SPT=53 DPT=36247 LEN=91 Sep  1 15:16:12 flower kernel: [  141.694208] New Input packets: IN=wlo1 OUT= MAC=b8:81:98:cb:ef:a8:5c:77:77:6e:0d:7b:08:00 SRC=172.67.68.8 DST=192.168.1.2 LEN=52 TOS=0x18 PREC=0x60 TTL=56 ID=0 DF PROTO=TCP SPT=443 DPT=50048 WINDOW=65535 RES=0x00 ACK SYN URGP=0 Sep  1 15:16:12 flower kernel: [  141.722991] New Input packets: IN=wlo1 OUT= MAC=b8:81:98:cb:ef:a8:5c:77:77:6e:0d:7b:08:00 SRC=192.168.1.1 DST=192.168.1.2 LEN=147 TOS=0x00 PREC=0x00 TTL=64 ID=32522 DF PROTO=UDP SPT=53 DPT=51721 LEN=127 Sep  1 15:16:12 flower kernel: [  141.743011] New Input packets: IN=wlo1 OUT= MAC=b8:81:98:cb:ef:a8:5c:77:76:6e:0d:7b:08:00 SRC=172.67.68.8 DST=192.168.1.2 LEN=40 TOS=0x18 PREC=0x60 TTL=56 ID=3764 DF PROTO=TCP SPT=443 DPT=50048 WINDOW=66 RES=0x00 ACK URGP=0 Sep  1 15:16:12 flower kernel: [  141.743028] New Input packets: IN=wlo1 OUT= MAC=b8:81:98:cb:ef:a8:5c:77:76:6e:0d:7b:08:00 SRC=172.67.68.8 DST=192.168.1.2 LEN=2840 TOS=0x18 PREC=0x60 TTL=56 ID=3765 DF PROTO=TCP SPT=443 DPT=50048 WINDOW=66 RES=0x00 ACK PSH URGP=0 More logs from router with illegal MAC address here:  nftables logs from illegal router
Routers often have multiple virtual network interfaces, and the MAC address that gets assigned to these is made by flipping some bits of the hardware MAC address. So the "illegal router" you see is probably another virtual interface of your "legal router". And if you block the packets (which are "legal" packets) then your "legal" router will stop to work. If there really was an "illegal router" somewhere in your home, you should be able to physically see and touch it, shouldn't you?
Delete illegal router from network
1,464,617,834,000
I have a network with 20 raspberries (clients) and 1 server. I'd like to check MAC of client request, is that possible ? Further, possible without being known (nor visible) by the client ? NB : I aim to check if a client is not a fake one/imitation. NB2 : I already run a VPN option. But I want to check MAC anyway.
Is your server a Linux host? If you have a white list of your clients, you can use iptables to accept requests only from them on specific input ports. You can also log requests from bad clients in dmesg. The following script defines MACCHECK chain to accept packets from approved 3 MACs, and drop others with logging. Then routes all packets of tcp/80 or tcp/443 in INPUT chain to MACCHECK. iptables -N MACCHECK iptables -A MACCHECK -m mac --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT iptables -A MACCHECK -m mac --mac-source yy:yy:yy:yy:yy:yy -j ACCEPT iptables -A MACCHECK -m mac --mac-source zz:zz:zz:zz:zz:zz -j ACCEPT iptables -A MACCHECK -m limit --limit 3/hour -j LOG --log-prefix "Bad host: " iptables -A MACCHECK -j DROP iptables -A INPUT -p tcp -m tcp --dport 80 -j MACCHECK # Checking all HTTP requests iptables -A INPUT -p tcp -m tcp --dport 443 -j MACCHECK # Checking all HTTPS requests Note that all your clients should be in the same network as your server's.
Get MAC of a client request?
1,464,617,834,000
I have been working on basic Linux network configuration. I am aware that IP addresses, default gateways, subnetmasks etc are assigned by a DHCP server but am unsure if MAC addresses are assigned by DHCP. Where do MAC addresses come from if a system is utilising DHCP?
The MAC address is a unique identifier that identifies the hardware (the network card)(the first bytes identify the manufacturer and type, the rest is a serial number). DHCP allocates an IP address to a MAC address. In other words, on all networks you PC has the same MAC address, but can be given different IP address by the DHCP servers. The uniqueness of the MAC is sometimes used to whitelist/blacklist computers on a network, although it can be worked around since you can sometimes replace the hardware MAC by an arbitrary value.
Does a DHCP server assign MAC addresses to network computers?
1,464,617,834,000
I wanna block a mac address which downloaded value is over "20480": The json file: { "client_length": 3, "clients": { "ac:07:5f:77:40:e9": { "id": 1, "ip": "192.168.5.40", "mac": "ac:07:5f:85:40:e9", "added": 1576258952, "active": 1576264642, "duration": 5711, "token": "4d8fd3ce", "state": "Authenticated", "downloaded": 45059, "avg_down_speed": 63.12, "uploaded": 2976, "avg_up_speed": 4.17 }, "ac:e0:10:55:2d:78": { "id": 2, "ip": "192.168.5.132", "mac": "ac:e0:10:12:2d:75", "added": 1576258985, "active": 1576264663, "duration": 5678, "token": "35dfa494", "state": "Authenticated", "downloaded": 18663, "avg_down_speed": 26.3, "uploaded": 4986, "avg_up_speed": 7.03 }, "58:48:44:db:ba:ba": { "id": 3, "ip": "192.168.5.93", "mac": "58:48:22:db:ba:be", "added": 1576258973, "active": 1576264662, "duration": 5690, "token": "139fede2", "state": "Authenticated", "downloaded": 187876, "avg_down_speed": 264.15, "uploaded": 7910, "avg_up_speed": 11.12 } } } In addition, this is the result of ndsctl json and it's always going to be changed. ndsctl is part of the nodogsplash package. I've installed this package on OpenWrt (BusyBox v1.28.4). My objective: The json above gives me some information. According to this file, I wanna block ac:07:5f:77:40:e9 and 58:48:44:db:ba:ba because the downloaded value of them is over that "20480". I need a bash script to do that for me. The commands to block mac addresses: ndsctl block ac:07:5f:77:40:e9 ndsctl block 58:48:44:db:ba:ba I've done something: root@OpenWrt:~# cat test.json | grep "mac\|downloaded" "mac":"ac:07:5f:85:40:e9", "downloaded":45059, "mac":"ac:e0:10:55:2d:78", "downloaded":18663, "mac":"58:48:44:db:ba:ba", "downloaded":187876, Any idea?
There is a JSON parser for the command line called jq readily available for most Unices (this may have to be installed from your package system). With it, it's easy to parse out the MAC addresses of the entries that have been downloaded more than 20480 times. Once these are fetched, you may just pass these off one by one to ndsctl block using xargs: jq -r '.clients[] | select(.downloaded > 20480).mac' file.json | xargs -n 1 ndsctl block This assumes that the JSON document is kept in file.json. For the given JSON document, this would run the two commands ndsctl block ac:07:5f:85:40:e9 ndsctl block 58:48:22:db:ba:be
Read a json file and run a command in Bash
1,464,617,834,000
Using one Ubuntu machine with one physical NIC, I want to make it seem that there are two or more additional machines on my real network, all controlled by this one Ubuntu machine. For example, I have a 192.168.1.x network. My Ubuntu machine has an IP of 192.168.1.10 with a mac address of 00:11:22:33:44:55. I want to make deploy another "machine" with an IP address of 192.168.1.11 and a mac address of 55:44:33:22:11. Therefore, when I arp-scan the local network from 192.168.1.9, it should display the following. ... 192.168.1.10 00:11:22:33:44:55 192.168.1.11 55:44:33:22:11:00 ... Both machines need to respond to ping as well from other real machines on my real network. The idea is to make it seem to 192.168.1.9 that there .10 and .11 are two independent machines on the real network. Looking for a relatively simple set of commands that would create this "machine", without creating any additional virtual machines or docker containers. Thanks in advance for your help!
I have a system with address 192.168.1.175: # ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 2c:f0:5d:c9:12:a9 brd ff:ff:ff:ff:ff:ff altname eno2 altname enp0s31f6 inet 192.168.1.175/24 brd 192.168.1.255 scope global dynamic noprefixroute eth0 valid_lft 80184sec preferred_lft 80184sec inet6 fe80::ed9c:756f:92a:ef21/64 scope link noprefixroute valid_lft forever preferred_lft forever We're going to add a macvlan interface with the address 192.168.1.190 and demonstrate that it has a different MAC address. Create a network namespace: ip netns add ns0 Create a macvlan device linked to your primary NIC and place it inside the ns0 namesapce: ip link add macvlan0 netns ns0 link eth0 type macvlan mode bridge This gets us: # ip -n ns0 link show macvlan0 6386: macvlan0@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether c2:f9:01:dd:eb:95 brd ff:ff:ff:ff:ff:ff Assign an address to the new interface: ip -n ns0 addr add 192.168.1.190/24 dev macvlan0 And bring up the interface: ip -n ns0 link set macvlan0 up From another system on the network: pi@retropie:~ $ sudo arp-scan 192.168.1.175 192.168.1.190 Interface: wlan0, datalink type: EN10MB (Ethernet) Starting arp-scan 1.9.5 with 2 hosts (https://github.com/royhills/arp-scan) 192.168.1.175 2c:f0:5d:c9:12:a9 (Unknown) 192.168.1.190 c2:f9:01:dd:eb:95 (Unknown) 3 packets received by filter, 0 packets dropped by kernel Ending arp-scan 1.9.5: 2 hosts scanned in 4.221 seconds (0.47 hosts/sec). 2 responded I can also ping the new address: pi@retropie:~ $ ping 192.168.1.190 PING 192.168.1.190 (192.168.1.190) 56(84) bytes of data. 64 bytes from 192.168.1.190: icmp_seq=1 ttl=64 time=25.3 ms 64 bytes from 192.168.1.190: icmp_seq=2 ttl=64 time=13.5 ms 64 bytes from 192.168.1.190: icmp_seq=3 ttl=64 time=10.5 ms ^C --- 192.168.1.190 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 6ms rtt min/avg/max/mdev = 10.520/16.424/25.270/6.371 ms
Unique Mac address for Secondary IP address?
1,464,617,834,000
I am running OpenWrt (=Busybox per SSH) so my amount of binaries is limited. I would like to change my MAC address only using a text editor like nano.
As you can see here, you should add the option macaddr in /etc/config/network in your desired interface. For example: config interface 'lan' option ifname 'eth0.1' option proto 'dhcp' option macaddr 'xx:xx:xx:xx:xx:xx' After that, restart the network service with /etc/init.d/network restart or reboot the device.
How to change eth0 MAC address only using a text editor?
1,464,617,834,000
For experimentation purposes I have bought some pairs of wifi and bluetooth devices and I plan to get some more. However when two or more of the same type are plugged in to the hub lsusb lists multiple instances of the device. Eg. a Realtek wifi adapter as the USB id 0bda:f179. If there are 3 of them this id will appear 3 times. What means of has Linux got for identifying them uniquely, not just when they are plugged in the same machine, but in other machines as well? Network adapters for instance have their MAC address stamped on them, and USB disk drivers also have some IDs linked with them, but I don't know about these wireless dongles and bluetooth devices. I would expect it to be their MAC addresses but in the wireless adapters it was always different when they connected to my access point, and even in the ifconfig listing. I suspect Linux was giving them new MACs each time, unless it was the devices themselves. Does the USB standard specify away for identifying each device uniquely, regardless of what type it is?
In Linux, you can use the udev system to assign unique identifiers to USB devices based on various criteria such as the device's vendor and product IDs, its serial number, or its physical location on the system's USB bus. This allows you to uniquely identify devices even if they have the same USB ID. To find the MAC address of a wireless network adapter, you can use the ip or ifconfig command. However, as you have noted, the MAC address may change depending on the network to which the device is connected. This is because some wireless adapters use randomized MAC addresses for privacy reasons. Bluetooth devices also have unique identifiers called Bluetooth device addresses (BD_ADDRs), which are similar to MAC addresses. You can use the hcitool or bluetoothctl command to view the BD_ADDR of a Bluetooth device. Regarding the USB standard, it does specify a unique serial number for USB devices, but not all devices have one. If a device does have a serial number, you can use it to uniquely identify the device. However, if the device doesn't have a serial number, you can still use other criteria such as the vendor and product IDs to differentiate it from other devices with the same USB ID.
How are USB devices uniquely distinguished?
1,464,617,834,000
I'm using a gateway connected to VPN to do forwarding with the port of an industrial LAN element. I use iptables forwarding to access port 80/443 of my gateway in the browser to show me the contents of Port 80/443 of the item: iptables -t nat -A POSTROUTING -p tcp -d 192.168.1.37 --dport 80 -j MASQUERADE iptables -t nat -A POSTROUTING -p tcp -d 192.168.1.37 --dport 443 -j MASQUERADE iptables -t nat -A PREROUTING -i br0 -p tcp --dport 80 -j DNAT --to 192.168.1.37:80 iptables -t nat -A PREROUTING -i br0 -p tcp --dport 443 -j DNAT --to 192.168.1.37:80 The problem is that that element sometimes changes local IP address, either by rebooting the router or by expiration on the DHCP server; for which we do not have access. To do this I would like to know if it is possible to make the forward instead of By Your IP address by your MAC. I tried to do something like that but it doesn't work: iptables -t nat -A POSTROUTING -p tcp -m mac --mac-source AA:BB:CC:DD:EE:FF --dport 80 -j MASQUERADE, throwing iptables: Invalid argument. Run 'dmesg' for more information. UPDATE WITH SCRIPT To solve this problem I have developed a script in bash that checks the MAC address and returns its IP address to create the iptables rules. The main idea is to launch the script from time to time using crontab. This is the script: #!/bin/bash vpnip=10.2.10.1 subred=192.168.1.0/24 mac=aa:bb:cc:11:22:33 # lowercase ip=$(nmap -sP $subred >/dev/null && arp -an | grep $mac | awk '{print $2}' | sed 's/[()]//g') if [ $ip ]; then echo "IP address found: $ip" iptables -t nat -A POSTROUTING -p tcp -d $ip --dport 80 -j MASQUERADE iptables -t nat -A POSTROUTING -p tcp -d $ip --dport 443 -j MASQUERADE iptables -t nat -A PREROUTING -i br0 -p tcp --dport 80 -j DNAT --to $ip:80 iptables -t nat -A PREROUTING -i br0 -p tcp --dport 443 -j DNAT --to $ip:443 iptables -t nat -A PREROUTING -d $vpnip -p tcp -m multiport --dports 80,443 -j DNAT --to-destination $ip:80 iptables --table nat --list else echo "IP not found" fi The script works properly. But, when the iptables rules are periodically released, they are duplicated. Is there any way to check the existence of these rules before writing them again? Or delete them before you do?
Is there any way to check the existence of these rules before writing them again? Or delete them before you do? You can use -C option for iptables. Check man iptables for more information. I think a neat way would be to create an array with the rules and check the rule for existence before you add it to the chain. Example script: #!/bin/bash ip='1.1.1.1' ip2='8.8.8.8' rules=( "INPUT -s $ip -j DROP" "INPUT -s $ip2 -j DROP" ) for rule in "${rules[@]}"; do if ! iptables -C $rule 2> /dev/null; then echo "Adding rule \"$rule\"" iptables -A $rule fi done
Changing `iptables` rules by `MAC` address
1,464,617,834,000
I have a samba share and I want to make some changes for security. Today everybody can read and write my files. It's not safe. I'd like to do the these things: 1- set up for everybody just read files 2- set and allow just to people with their IPs & Mac Address allowed to write
If you want to give only read permission and not write permission, open up your configuration file, the path to which is /etc/samba/smb.conf Inside this file, move down to the share name of your directory. Now there must be an option write list. Either comment this or remove this option. This will now not allow anyone to write. To give read permissions, use these 2 options - brosweable=yes valid users=User1 user2 user3 Now to allow only hosts from particular IP addresses, use option hosts allow. hosts allow=IP_of_host. For example, if share name of your directory is abc, then your configuration for this file should like this: [abc] path=/abc browseable=yes valid users=john mike hosts allow=127.0.0.0/24 // it must be IP of hosts you want to allow Save your configuration file, enable service samba on firewall, and restart services smb nmb .
Samba share security changes: read-only and IP/MAC restrictions
1,464,617,834,000
I upgraded to Fedora 40 and was introduced to its new feature of MAC address randomization (for Wi-Fi interfaces at least). How do I disable it? Links I found didn't work for me: https://discussion.fedoraproject.org/t/f40-change-proposal-wifi-mac-randomization-system-wide/99856/5 https://fedoraproject.org/wiki/Changes/StableSSIDMACAddress I tried to follow the advice from link 2 and create 2 files in /etc/NetworkManager/conf.d/: 22-wifi-mac-addr.conf: [connection.22-wifi-mac-addr] match-device=type:wifi wifi.cloned-mac-address=stable-ssid [.config] enable=nm-version-min:1.45 and 90-wifi-mac-addr.conf: [connection-90-wifi-mac-addr-conf] wifi.cloned-mac-address=permanent I followed instructions literally: e.g. the 22* file has section named [connection.22-wifi-mac-addr] while the 90* file has one named [connection-90-wifi-mac-addr-conf] (i.e. the dot and minus after the word 'connection', present and absent '-conf' suffix etc.). Also I tried to make it uniform, sort of to fix all of the typos. Nothing, after I restarted the NetworkManager.service: # systemctl restart NetworkManager.service the MAC address keeped to change on every enable/disable Wifi toggle. Could someone help me please?
I tried to follow the advice from link 2 and create 2 I don't think that is what link 2 suggests. The Fedora change introduces a new file /usr/lib/NetworkManager/conf.d/22-wifi-mac-addr.conf. That's all. You can prevent that file from being loaded at all, by creating a file /etc/NetworkManager/conf.d/22-wifi-mac-addr.conf. That file can be empty, or contain additional configuration. Of course, you can drop any other configuration snippets (preferably sorted after "22*"), to overwrite that configuration. Configuration snippets are loaded in a documented order, where later files overwrite earlier ones. See man NetworkManager.conf. Also, it's possible that the best choice is not to change the default back. Instead, modify the few profiles that should use a certain MAC address. For example with nmcli connection modify "$PROFILE" wifi.cloned-mac-address permanent. You probably should do that instead. the MAC address keeped to change on every enable/disable Wifi toggle. Are you sure about that? Note that while NetworkManager is not connected, the MAC address also gets randomized. That is nothing new. Did you check that the MAC address also changes while being connected? You could disable the randomization during scanning via wifi.scan-rand-mac-address. See man NetworkManager.conf. But there should be no need to do that.
How to disable MAC address randomization in Fedora 40?
1,464,617,834,000
I need to set the default gateway's MAC address statically. I used the command: arp -s <ip> <mac> That works, but on reboot the entry is back to being dynamic. I have tried: Writing the same arp -s <ip> <mac> command inside a script, in the /etc/network/if-up.d directory This seemed straightforward, but it didn't work. When rebooting, the arp entry is back to being dynamic. Looking at the configuration inside /etc/systemd/network/eth0.network, it contains: [Match] Name = eth0 [Network] Description = Interface eth0 autoconfigured by PVE Address = <ip> Gateway = <ip> DHCP = no IPv6AcceptRA = false I don't really know how I could change this configuration.
You would have to add this to your /etc/systemd/network/eth0.network file: [Neighbor] Address=<gateway IP> LinkLayerAddress=<gateway MAC> But the Description = Interface eth0 autoconfigured by PVE suggests this file may be managed by some other software, so it is possible any changes to it may be overwritten. Is this a virtual machine under Proxmox Virtual Environment? A script in /etc/network/if-up.d would apply if you used a classic Debian ifupdown package to manage your network interfaces. But it seems you are (or Proxmox is) using plain systemd-networkd instead. I don't know about Proxmox; anyone reading this, feel free to comment or write an answer of your own if you have a better Proxmox-compatible way to configure a static MAC address for a neighboring host persistently. If there is no better way, you could of course define a custom service to run after regular network set-up, which would execute the required arp -s command. Such a service definition might look like this: [Unit] Description = Set gateway MAC address statically After = network.target network-online.target Wants = network-online.target [Service] Type = oneshot RemainAfterExit = yes ExecStart = /usr/sbin/arp -s <gateway IP> <gateway MAC> # Alternative command to set gateway MAC without the legacy arp command: # ExecStart = /sbin/ip neigh add <gateway IP> lladdr <gateway MAC> nud permanent router [Install] WantedBy = multi-user.target You might place it to e.g. /etc/systemd/system/gatewayMAC.service.
How do I set a static MAC address for the default gateway on startup?
1,464,617,834,000
I want to match every traffic from a server but it is at the same interface. MAC 88:7e:25:d3:90:0b > ens19 > table 147 Therefore I made this nftables rule table ip filter { # handle 3 chain input { # handle 1 type filter hook input priority filter; policy accept; iif "ens19" ether saddr 88:7e:25:d3:90:0b meta mark set 0x00000093 # handle 2 iif "ens19" ether saddr 08:05:e2:04:ce:b3 meta mark set 0x00003417 # handle 3 } } And ip rule for specify routing table ip rule add from all fwmark 0x93 lookup 147 ip rule add from all fwmark 13335 lookup 147 ip -6 rule add from all fwmark 0x93 lookup 147 ip -6 rule add from all fwmark 13335 lookup 147 But I use tshark to see if it works, it shows there is no incoming packages and I can't ping the address. So something is wrong with matching income flow. And if I use from all iif ens19 lookup 147 instead of ip -6 rule add from all fwmark 0x93 lookup 147 ip -6 rule add from all fwmark 13335 lookup 147 it works, so it must be something wrong with my nftables rules. Does anyone know why?
hook input is specifically meant for packets where the local host is the final destination – it is only reached after routing decisions have been made, as that's how netfilter knows which packets are processed through "hook input" chains and which ones go through "hook forward" chains. So at that point, your policy rules no longer matter. Instead, I think you need hook prerouting (and probably with priority raw?).
MAC based routing with nftables and ipv6
1,464,617,834,000
I have set up a DHCPD service on a Linux server, which shall provide fixed public IP addresses for cable modem devices based on MAC addresses. Here is the configuration file of the DHCPD. The server's IP address is 212.200.200.34 (it has only one interface) and the CMTS has the IP address 172.30.30.2. The CMTS and the DHCP servers are in the same VLAN 2000. ddns-update-style none; option domain-name-servers 8.8.8.8, 8.8.4.4; default-lease-time 23200; max-lease-time 86400; lease-file-name "/var/db/dhcpd.leases"; authoritative; log-facility local7; shared-network CMTS-PUBLIC-IPS { subnet 212.200.200.32 netmask 255.255.255.224 { option dhcp-server-identifier 212.200.200.34; server-identifier 212.200.200.34; option routers 212.200.200.33; option subnet-mask 255.255.255.224; option time-servers 212.200.200.34; range 212.200.200.36 212.200.200.62; option broadcast-address 212.200.200.63; server-name "212.200.200.34"; option domain-name "bla"; host SID-900111 { hardware ethernet 55:47:6d:ed:03:c9; fixed-address 212.200.200.36; } host SID-111334 { hardware ethernet 61:5a:6d:ef:cb:b4; fixed-address 212.200.200.37; } ... } subnet 212.100.100.96 netmask 255.255.255.224 { option dhcp-server-identifier 212.200.200.34; server-identifier 212.200.200.34; option routers 212.200.200.33; option subnet-mask 255.255.255.224; option time-servers 212.200.200.34; range 212.100.100.97 212.100.100.126; option broadcast-address 212.100.100.127; server-name "212.200.200.34"; option domain-name "bla"; host SID-111109 { hardware ethernet 21:4e:6c:ac:09:43; fixed-address 212.100.100.97; } host SID-111110 { hardware ethernet 53:4e:6d:da:38:0a; fixed-address 212.100.100.98; } ... } } So, the addresses of the first range (212.200.200.36 - 212.200.200.62) are given out correctly to the devices. The addresses of the second range (212.100.100.97 - 212.100.100.126) are not, stating an error in the logs: wrong network. Can you tell me, what I am missing here? I created a simple graphic file. The DHCP A is not important. The problem exists in DHCP B.
Alright, I had two ways now to do it: Either add another NIC to the machine with an IP of the second IP range or try to get a bigger IP range (/26 instead /27). First, I tried it with the second NIC, which worked out fine. Later on I received a /26 net and reconfigured everything, so all CMs are in the same net. Both methods are legit/working.
DHCPD with two different ranges
1,464,617,834,000
This perl line very useful to change mac address but retain the first three pair. perl -e 'for ($i=00;$i<6;$i++){@m[$i]=int(rand(256));} printf "00:16:3E:%X:%X:%X\n",@m;' Generate some good address 00:16:3E:1E:B6:DB 00:16:3E:EE:8D:4A But some with only one figure(E,D) 00:16:3E:80:21:D 00:16:3E:18:87:D 00:16:3E:E6:EF:5 00:16:3E:E:99:6A I want all with two figures,for example the bad become 00:16:3E:80:21:D1 00:16:3E:18:87:4E 00:16:3E:E6:EF:5A How to do?
This solution seems to work: %X become %02X Old and not working perl -e 'for ($i=00;$i<6;$i++){@m[$i]=int(rand(256));} printf "00:16:3E:%X:%X:%X\n",@m;' new and working perl -e 'for ($i=00;$i<6;$i++){@m[$i]=int(rand(256));} printf "00:16:3E:%02X:%02X:%02X\n",@m;'
Perl script for generating MAC addresses
1,464,617,834,000
Let's say I'm browsing from Ubuntu Virtual Machine using Firefox. IF the website I am visiting can see the MAC Address, which MAC address will it see? Is MAC Address of Ubuntu VM or MAC Address of the host Operating System?
The website you are visiting can't see the MAC address of your computer, unless it is at the same LAN. For a computer on the same LAN, it depends on your VM settings. Bridged access will see the MAC of the guest, while NAT access will see the MAC of the host.
Virtual Machine MAC Address or Host Operating System MAC Address?
1,464,617,834,000
arp -a doesn't show it. How can I get the MAC of it then? (on ex.: from a Linux)
If your switch is a managed switch, then you can use lldpctl from the lldpd package (on Debian/Ubuntu) to know its MAC address. The lldp package is described as follows: lldpd is a 802.1ab implementation (LLDP) to help you locate neighbors of all your equipments. The man page for lldpctl shows how to use it: NAME lldpctl — control LLDP daemon SYNOPSIS lldpctl [-d] [-L location] [-P policy] [-O poe] [-o poe] [interface ...] DESCRIPTION The lldpctl program controls lldpd(8) daemon. When no specific option is given, lldpctl displays the list of discovered neighbors along with some of their advertised capabilities. If some interfaces are given, only those interfaces will be displayed. ... References lldp website Additional packages for other distros
How to get switch MAC address if it's a layer2 one?
1,412,767,588,000
Whats the difference between mail and mailx? I'm trying to troubleshoot a problem where I can send mail from server A with this echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS command but executing the same command from server B throws me this error (Both servers are RHEL) mail: invalid option -- r Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ... [-- sendmail-options ...] mail [-iInNv] -f [name] mail [-iInNv] [-u user] Now... going through mail manpages to ty to understand whats happening, man mail gives me this: In Server A MAILX(1) User Commands MAILX(1) NAME mailx - send and receive Internet mail SYNOPSIS mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops] [-A account] [-S variable[=value]] to-addr . . . mailx [-BDdeEHiInNRv~] [-T name] [-A account] [-S variable[=value]] -f [name] mailx [-BDdeEinNRv~] [-A account] [-S variable[=value]] [-u user] But in server B MAIL(1) BSD General Commands Manual MAIL(1) NAME mail - send and receive mail SYNOPSIS mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr... [-- sendmail-options...] mail [-iInNv] -f [name] mail [-iInNv] [-u user] Now... if I try man mailx in server B I get: MAILX(P) POSIX Programmerâs Manual MAILX(P) PROLOG This manual page is part of the POSIX Programmerâs Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be imple- mented on Linux. NAME mailx - process messages SYNOPSIS Send Mode mailx [-s subject] address... Receive Mode mailx -e mailx [-HiNn][-F][-u user] mailx -f[-HiNn][-F][file] Server B has a different version of mail than Server A? Mailx and Mail are different things? I would like to use the -r option I use in server A but in server B and I don't really know whats happening.
Behold the confusing history of mail, nail, mailx. Briefly, mail is the older program, mailx (formerly nail in some implementations) is a newer version , with an extended mostly-but-not-totally-compatible interface. mailx is still quite old, created around 1986 and standarized as part of POSIX in 1992. There are several implementations (even in modern Linuxes), and some provide extensions to the standard. The -r option is one such extension. Depending on your Linux distribution, and the mail package you have installed, you might or not have that option. See eg here. If you want to write portable scripts, it's better not to rely on it.
Difference between mail and mailx? [duplicate]
1,412,767,588,000
I know we can use mail command in terminal to start using the mail program in interactive mode. However, I want to read the email using mail command non-interactively. Is there a command like $ mail -optionToReadMail -mailNumber 1; which will display the content of email in stdout ?
To print the first mail message in your default mailbox, use: echo p | mail mail is only interactive when stdin is a terminal. Because mail gets its stdin from a pipe, it is non-interactive. The p command (print) tells it to print the default (first) message. For more options, you may find that man mail is very helpful.
use 'mail' to read email from command line
1,412,767,588,000
I'm trying to send unix mail (heirloom-mailx) via bcc. $ mail -V 12.5 6/20/10 My MTA is exim, which sends via Gmail SMTP. I can execute the following: echo -e "body" | mail -s 'subject' -b [email protected],[email protected] [email protected] All addresses receive the email, however the bcc is not hidden. i.e. in the email to [email protected], I still see: To: [email protected] Bcc: [email protected],[email protected] How can I make mail send bcc properly?
heirloom-mailx hardcodes the options to pass to /usr/sbin/sendmail, and unfortunately the ones it passes don't make Bcc: headers work right in exim. That isn't really fixable, without patching and recompiling it. (You need to have it add -t to the arguments, and then either not pass the list of email addresses or alternatively set extract_addresses_remove_arguments = false in your exim config). There is an easier solution: just have it send via SMTP. You do this by setting the smtp option, and since you've got a local MTA running, you should be able to set it to localhost. You can test like this: $ mail -S smtp=localhost -s 'test message' -b [email protected] [email protected] la la la . If that works, you can put the smtp option in /etc/nail.rc (system-wide) or ~/.mailrc (per-user). Note that nail.rc, with an n, is not a typo.
How can I bcc with mailx?
1,412,767,588,000
I had a problem that gmail was blocking emails sent using mailx. I solved this by setting up an appropriate ~/.mailrc, which looks like: set smtp-use-starttls set nss-config-dir=/home/theuser/.certs set ssl-verify=ignore set smtp=smtp://smtp.gmail.com:587 set smtp-auth=login set smtp-auth-user=xxx set smtp-auth-password=yyy set from="[email protected](Rabbit Server)" So now when I run: echo "hi" | mailx [email protected] my emails send successfully as user and as root. Now I want cron to work as well. I changed "/etc/sysconfig/crond" to force it to use mailx, with: CRONDARGS="-m /usr/bin/mailx" I have ~/.mailrc setup at: /root/.mailrc /home/theuser/.mailrc /etc/.mailrc But no matter what I do, echo output is not emailed successfully. The crontab looks like (and I've checked, the scripts are running and doing their job, and echoing, just cron isn't sending emails): MAILTO="[email protected]" # Every minute check processes are running, restart if necessary and send an email. * * * * * source /home/theuser/.bashrc; global audit_regular # Every day, send an email describing the state of the host and its jobs. 0 5 * * * source /home/theuser/.bashrc; global audit_daily # Every Monday at 7am, archive the logs. 0 7 * * 1 source /home/theuser/.bashrc; global archive_logs Also, this crontab is setup on another host and sending emails fine.
mailx only sends mail if you pass it the destination address on the command line. When you run it with no arguments, it reads interactive commands from its standard input. Beware that your tests fed it garbage which has been interpreted as commands; some of these commands may have corrupted your mailboxes, sent out emails, etc. Tell mailx to run mailx -t, which expects a full email with headers on standard input. From a cursory examination, it doesn't look like you can pass a command with parameters via the crond startup script. So write a shell wrapper /usr/local/sbin/mailx-t #!/bin/sh exec mailx -t and put CRONDARGS="-m /usr/local/sbin/mailx-t" in /etc/sysconfig/crond.
Calling mailx from crond
1,412,767,588,000
I was trying to send an email to multiple persons using mailx (mailx (GNU Mailutils) 3.4). I did that successfully on a previous version of Ubuntu, v16.04, and the script was working fine. Now I have Ubuntu 18.04 and the following problem: mailx: unrecognized option -S mailx: unrecognized option -S mailx: unrecognized option -S what should I do? My script is as follow: #!/bin/bash FILE="speakers.csv" while IFS=";" read name mailAdress do printf "Dear $name, \n\n something something... " | mailx -s "Title" -S smtp=smtps://mySMPTadress -S smtp-auth=login -S smtp-auth-user="MyUserName" -S smtp-auth-password='MyPassword' -S from="MyName <MyEmailAdress>" mailAdress done < "$FILE" file speakers.csv looks like this Klaus A;klaus@*****.de Alessandra B;alessandra@****.it Serge C;serge@****.fr
Quick and dirty: mailx is a link to s-nail so you should use s-nail instead as according to its Bionic man page it still has the -S option. Do it properly: You should avoid sending mail like that because anyone that has access to ps can read your password as it's on the command line and you should look into using the -A (account) option to store this in the .netrc file that only the user and root have access to. (Read the full man page)
Ubuntu 18.04: Error with mailx smtp - mailx: unrecognized option "-S'"?
1,412,767,588,000
I would like to download all the e-mails in my old e-mail server. It uses POP3 and I'm interested in e-mails in "Inbox" and "Sent" folders. Once I have downloaded all the messages, I would like to make a script which lists all the e-mails between my e-mail address and one certain e-mail address in chronological fashion into single text file. However, at first, I think I need to download all the messages to a single file with headers including dates and then create a sorting script. How to approach this? I have used mailx in scripts for sending mails, but is it possible to use mailx to download all the mails from POP3 server into a single file?
Traditional mailx does not support IMAP or POP, but the one that comes with Linux does. For your particular problem, I recommend using fetchmail instead. You can use the --mda option to have fetchmail execute a script of your choice for each downloaded message. It can even pass the From and To addresses as parameters to your script if you use %F and %T as placeholders in the command line. First, create a mailsorter script: #!/bin/sh dest_mbox="$1" from="$2" to="$3" case "$from-$to" in [email protected]) echo "From $from `date`" >> "$dest_mbox" cat >> "$dest_mbox" ;; *) cat > /dev/null ;; esac Then run fetchmail -u myname popserver.example.com --mda './mailsorter /tmp/mbox %F %T' While testing this solution, give fetchmail the --all and --keep flags to make sure that you don't delete your mail accidentally.
How to download all the e-mail messages from POP3 server to a single text file with mailx?
1,412,767,588,000
I can't install mailx on CentOS 9. yum install mailx -y Last metadata expiration check: 0:04:13 ago on Sat 09 Apr 2022 07:55:59 PM UTC. No match for argument: mailx Error: Unable to find a match: mailx
According to Bugzilla Bug 2001537 "mailx -> s-nail replacement in CentOS Stream 9", mailx was replaced by s-nail. There's also a reference to the same in the Red Hat's "Considerations in adopting RHEL 9" - Appendix A. Change to packages - Package replacements. Install the replacement package with: yum install s-nail.
Install mailx on CentOS 9
1,412,767,588,000
I am using mailx command to send mail, I tried it by two ways.. mailx -s "This is Subject" toAddr < bodyFile.txt mailx -r "fromAddr" -s "This is Subject" toAddr < bodyFile.txt I am getting same error: send-mail: fatal: parameter inet_interfaces: no local interface found for ::1 I want to know how to resolve that error as well as following things: What does mailx takes fromAddress by default? What does mailx takes Mail Transfer Agent address by default? From where to change these values?
Mailx is just a command-line tool to pass mail to your Mail Transfer Agent (MTA; whatever it is you have installed: sendmail, exim, ...). It does this by invoking the command sendmail (usually /usr/sbin/sendmail). Your MTA provides this command to, well, send mail. In your case, it tries to contact a server on the IPv6 address of the loopback device on localhost (::1), and can't find anything. So either your MTA is not configured correctly (uses IPv6 instead of IPv4), or your IPv6 networking setup is not correct (no ::1 address on loopback interface). The default from-address is your username, and the MTA adds whatever domain name you have configured in your MTA (and may further rewrite this according to various criteria like which mail server it contacts to deliver the mail, if you've set up rules for it). You change these values by configuring your MTA. I don't understand the question "what does mailx takes MTA address by default". If you mean "which MTA does it use", as I said, it just invokes the sendmail command, so it uses whatever MTA package you have installed that provides this command.
what things i should know when using mailx command
1,412,767,588,000
I'm trying to send an HTML email from our CentOS server to users. In the long run I'll be building a COBOL program that runs the command to send reports to the user. Here are a few details. CentOS 6.4 MAU : Mailx MTA : Postfix 2.6.6 Postfix is running a relay through an exchange server. As for what commands I've tried running. The one I've seen the most today has been the following. $ mailx -a 'Content-Type: text/html' -s "Command Line Test" [email protected] < ./bodytext.html After running the shown command, I get an error saying "Content-Type: text/html: No such file or directory". I'm pretty sure that after a certain update they stopped allowing -a as a flag for Content-Type designation. I've also tried adding the 'Content-Type: text/html' to the actual bodytext.html file as the very first line. I'm kind of just at a loss for what I can do to send the HTML email. Some of the sources I've found say that mailx and postfix can't properly send HTML emails. Hopefully that's not the case, but if it is than I'd like to know what your take on other MAU and MTA technologies?
Since you seem to have full control over the generated text file, the simplest and probably most portable way would be to involve /usr/sbin/sendmail directly. /usr/sbin/sendmail -t < complete-mail.txt This would require you to add all important headers yourself (From, To, Subject, and Content-Type). The file should look like this: From: Company <[email protected]> To: Customer <[email protected]> Subject: You are awesome Content-Type: text/html <html>…</html> Postfix will add missing but required headers like Date.
Sending HTML using mailx with postfix 2.6.6 and centOS 6.4 [duplicate]
1,412,767,588,000
Having many short mail messages in my inbox, it's quite annoying that even short messages are sent though a pager (less), requiring to press 'q' before I can view the next message (for example). I read the manual page about pager, but none of these did work: PAGER= mailx set pager= unset pager unset PAGER How can I disable the pager? I'm using mailx 12.5 of SLES 15 SP3.
There are two major problems that prevent an easy solution for the problem: As indicated in the mailx man page (SLES ships Nail’s mailx), “Variables in the environment passed to mailx cannot be unset.” PAGER (as set from within mailx) cannot have parameters, so something like set PAGER="LESS=-F less" or set PAGER="sh -c LESS=-F less" do not work. To make things worse, there is no output if you try something like set PAGER="less -F". So the alternatives are: mailx can be configured to skip the pager if a message fits in a single screen by setting the crt option (that requires the number of lines of the terminal normally): add set crt to your .mailrc. Without a value, the version of mailx available in SLES uses the current screen height; POSIX doesn’t specify the behaviour when crt is set without a value, so a POSIX-compliant approach is either to set it to 99999 (to always skip the pager) or a typical value for your work environment (to only use the pager when necessary). The pager can also be replaced with a non-paging display tool, e.g. cat when starting mailx from a Bourne-shell-like interpreter: PAGER=cat mailx If your pager is less, you can ask it to quit without prompting if it has less than a screen’s worth of text to display, using its -F option (again using sh syntax): LESS=F mailx If you want to combine -F with other options set in your LESS variable, use LESS="$LESS -F" mailx This can be enabled in general by exporting LESS=F (and any other less option you want to enable by default) in your shell startup script. In versions of less older than 530, you may need to combine -F and -X (LESS=FX).
How to avoid the "pager" in mailx?
1,412,767,588,000
How can I set up mailx to send messages to my Gmail account? What I do now is run the command: mail -s "hello kid" [email protected] It freezes and does nothing. I tried some variations, but all of them just froze dead in my terminal. Is there anything I need to configure in mailx before actually using mail? There were different options found on the Internet, like making a .mailrc and other config files, but I got nowhere. Can someone provide me with more information on the subject?
The command mail -s "hello kid" [email protected] is waiting for you to type the mail message and then control-d. After you do that the message will be sent. If you just want a quick test, do: echo `date` this is a test | mail [email protected] and the message will be sent immediately.
How to configure mailx to support Gmail?
1,412,767,588,000
Lets say I have 5 messages in /var/mail/ and I want to read one message at a time and then do some string search in that mail before moving on to the next message. Is there a command that I can use to parse one message at a time ? I am looking to write a bash script which will read all messages in an mbox file & then read them one at a time so that I can then extract Subject, To, From & Status of the message(bounceback code). My plan was to use grepmail to get count of emails in the file and then use this count in a for loop to get one mail at a time and them perform operation on the text. Something like: $count = grepmail -r . /var/mail/user | awk '{print $2}' for($i=1;$i<=$count;$i++) { $content = *GetMessage* -number $i /var/mail/user ... Do string operation on this message & save to $DelimitedData ... } $Delimiteddata I can't figure out how to pickup single message at a time to perform string operation on them. Can someone please guide me which command/program can help me do this non interactively.
The formail tool from procmail (available in any distribution, it's a classic) is designed precisely for this purpose. Basic usage: formail -s myprogram --option runs myprogram --option on each mail in turn. The program receives each mail on its standard input.
How can I read one message at a time from /var/mail
1,412,767,588,000
I have setup unattended-upgrades on servers running Raspbian (Raspbian GNU/Linux 9.4 (stretch)). Version of Unattended-upgrades: 0.93.1+nmu1 Updates work, but I am having problems with the email reporting. I want to use mailx for sending reports. If I run the update with command unattended-upgrade -v -d the report gets sent and it uses the email configuration I have in /root/.mailrc. When unattended upgrades are run by the Systemd timer (apt-daily-upgrade.timer), however, it won’t use mailx. If sendmail is present it is used to send the mail. In that case, the mail gets sent, but the sender is root@hostname and the messages get flagged as spam. If there is no sendmail I see this error in journal of apt-daily-upgrade: Cannot start "/usr/sbin/sendmail": executable not found (adjust *sendmail* variable) I cannot understand why different mail programs gets used depending on how the task was started. I have tried to edit unattended-upgrades Python program to force it use mailx: if os.path.exists(SENDMAIL_BINARY): ret = _send_mail_using_sendmail(from_email, to_email, subject, body) elif os.path.exists(MAIL_BINARY): ret = _send_mail_using_mailx(from_email, to_email, subject, body I changed the variable SENDMAIL_BINARY to point to a non-existing path so it would forced to use mailx. This too worked when invoked unattended-upgrades manually but failed when it was run by Systemd. (And the above error about trying to use sendmail still gets logged.) How can I force unattended upgrades to use mailx even when is run automatically by systemd and what is causing the difference in Mail program that gets used? EDIT: System unit file that runs Unattended upgrades: [Unit] Description=Daily apt upgrade and clean activities Documentation=man:apt(8) ConditionACPower=true After=apt-daily.service [Service] Type=oneshot ExecStart=/usr/lib/apt/apt.systemd.daily install KillMode=process TimeoutStopSec=900
Your question is a variation of the FAQ Why do things work differently under systemd?. One of the benefits of systemd is that it provides a consistent execution environment. To error on the side of security and simplicity, the environment variables set are minimal. The related docs on the systemd execution environment detail what's set. You mentioned that your configuration was in the root home directory. man mailx confirms It is looking in ~/.mailrc, as opposed to the fixed path /root/.mailrc. The systemd docs clarify that the $HOME variable is only set when the User= directive is used. You did not share your systemd service file, but I presume since you are running the task as root you did not use the User= directive. So that could explain part of your issue. It also appears that a path you want may not be set by your $PATH environment variable when run by systemd. You can confirm this by replacing the ExecStart= line in your service with: ExecStart=/bin/echo "My path is $PATH" If the mailx path is not listed, you can explicitly set with an Environment= directive. If this explicit tips don't solve your issue, be sure to check out the FAQ linked above for more possibilities.
Unattended upgrades won’t use mailx when run by Systemd
1,412,767,588,000
Say I receive a message with an attachment, and all I want to do is to resend this message to another address. Is it possible to do this using plain mailx? If so, how? I know Heirloom mailx has a resend command, but I was wondering if it is possible to achieve this result using more primitive versions of mailx.
According to heirloom mailx's documentation: resend: Takes a list of messages and a user name and sends each message to the named user. 'Resent-From:' and related header fields are prepended to the new copy of the message. For a bare-bones way to achieve the same effect, you don't even need to use an MUA at all. You can just use the shell and pipes to submit the message directly to the MTA/MSP. So if you have the message (headers+body) located in a file called foo: ( echo "Resent-From: your.email@address cat foo ) | /usr/lib/sendmail [email protected] Note that the MTA installed the system need not be Sendmail for this to work. /usr/lib/sendmail is just the defacto standard UNIX mail submission interface. Other MTAs like Postfix and exim provide /usr/lib/sendmail too. Also note that I did not take into account the "related header fields" mentioned in the documentation. I didn't check for I guess they are Resent-Date and things like that. If you know what they are and you care to include them, you can just add them as additional echo statements above. Finally, I'll note that even heirloom mailx has an additional mode called "Resend" (note capital R) documented as follows: Like resend, but does not add any header lines. This is not a way to hide the sender's identity, but useful for sending a message again to the same recipients. So if you actually want that, it's even simpler because you just submit the existing message as is: /usr/lib/sendmail somebody@else < foo
Can I resend a message with (plain) mailx?
1,412,767,588,000
On my Raspbian server, I wish to have local *nix mail delivered locally, as well as to an external address. /home/pi/.forward contains pi,[email protected]. I've run sudo dpkg-reconfigure exim4-config with the following options. mail sent by smarthost; received via SMTP or fetchmail. System mail name: raspberrypi. IP-addresses to listen on for incoming SMTP connections: 127.0.0.1 Other destinations for which mail is accepted: none. Machines to relay mail for: none. IP address or host name of the outgoing smarthost: smtp.bar.com:465 Hide local mail name in outgoing mail? Yes. Visible domain name for local users: bar.com Keep number of DNS-queries minimal (Dial-on-Demand): No. mbox format in /var/mail/ Split configuration into small files? No. Note that I've set the apparent sending domain as bar.com, as I suspect my SMTP server requires that. I've then added the associated credentials in /etc/exim4/passwd.client, i.e. smtp.bar.com:[email protected]:PASSWORD. Then I've run sudo update-exim4.conf; sudo invoke-rc.d exim4 restart; sudo exim4. Testing, if I send mail to an external address, it works fine. echo -e "Test body" | mail -s 'Subject' [email protected] I receive the mail at [email protected], and the sender is [email protected]. However, if I send it to the local address, it only goes to the local address. echo -e "Test body" | mail -s 'Subject' pi In this case, the sender is pi@raspberrypi, which probably makes the SMTP server reject it. How can I send mail to both the local server and the external?
With most mailers you can do something like this in the /etc/aliases file. joe: joe, [email protected] After making changes to this file you typically have to run the command, newaliases. References How to redirect local root mail to an external email address on Linux Forwarding email and must keep a copy
How can I forward local *nix mail to an external account while keeping the local copy?
1,412,767,588,000
By using find command I got multiple files. Now I want to add all these files as mail attachment. How do I add these files as attachment in single mail? I want to implement this in script. Do I need to use for loop and store the files in array variables? EX: I got 3 files results by the following find . -type f -name "sum*" result: sum123.pdf sum234.pdf sum453.pdf
You can do it with mutt like this: mutt -a $(find . -type f -name "sum*") If you want to do it non-interactive, try mutt -s "Subject" -a $(find . -type f -name "sum*") -- [email protected] < /dev/null If mutt is not installed, here is an example with mail and more tools (e.g. mpack)! So it should be something like #!/bin/bash # This needs heirloom-mailx from="[email protected]" to="[email protected]" subject="Some fancy title" body="This is the body of our email" declare -a attargs for att in $(find . -type f -name "sum*"); do attargs+=( "-a" "$att" ) done mail -s "$subject" -r "$from" "${attargs[@]}" "$to" <<< "$body" For a sh environment without declare: #!/bin/sh # This needs heirloom-mailx from="[email protected]" to="[email protected]" subject="Some fancy title" body="This is the body of our email" attargs="" for att in $(find . -type f -name "sum*"); do attargs="${attargs}-a $att " done attargs=${attargs::-1} mail -s "$subject" -r "$from" ${attargs[@]} "$to" <<< "$body"
Attach files for sending mail which are the result set of find command
1,412,767,588,000
On my computer, mail is stored in ~/Mailbox, not in a centralized directory. Is there a way to get bsd-mailx to read mail from there, instead of looking in /var/mail?
You can change the location of the mailbox in two ways. The first is using the MAIL environment variable: export MAIL=$HOME/Mailbox The other method is to use the -f option to mailx to specify a mbox file manually: mailx -f ~/Mailbox
Change mailx mailbox location
1,412,767,588,000
I know that you can change the from address in *nix mail by specifying command-line options. However, is there a way to set it globally, so that it is respected by forwarding? I tried modifying the $REPLYTO environment variable, but this did not help. Background I have set up my Raspbian mail to forward by configuring /etc/aliases. However, for external email recipients, the sender is [email protected], where pi is the Linux login name. I want to find a way to specify the username manually, to match my email account, [email protected]. My exim4 configuration is specified here. N.B. there is an option to specify the sender domain ("Visible domain name for local users: bar.com"), but not a way to specify the username for each account.
It sounds like you want Exim's address rewriting. In the rewriting section of your Exim config file, you will probably want something along the lines of this: [email protected] [email protected] Ffr You may need to adjust the flags ("Ffr") to the specific behavior you want. More generally, see: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-address_rewriting.html Raspbian Specifically, in Raspbian, edit /etc/exim4/exim4.conf.template, adding the following in the REWRITE CONFIGURATION section. [email protected] [email protected] Ffr If you prefer all outgoing email to be from [email protected], regardless of original sender, use this line instead. * [email protected] Ffr Next, run sudo update-exim4.conf, then check to make sure it worked with exim -brw [email protected]. This should print out a list of the headers after the rewrite rules have been applied.
How can I change the from address in *nix mail globally?
1,412,767,588,000
I am sending mail to a list of users, using the mailx utility: mailx -s "$SUBJECT" "$TO" < $FILE It is working fine with valid emails, but I am getting a dead.letter issue when I try to send mail like adffadf, i.e., the string is not a valid email, I want this dead.letter to not be occurring even for users having anything for email ID, e.g., [email protected], [email protected], adffdfs
The man page for my mailx says a lot of things about set nosave and so on, but they don't seem to work. The only way to stop your dead.letter file growing I have found is to replace it by a link to the special file /dev/null. rm ~/dead.letter ln -s /dev/null ~/dead.letter
dead.letter issue on Linux?
1,412,767,588,000
I need to send the generated CSV files on regular intervals using script. I am using UUENCODE and mailx for the same. But i need to know that is there any method/way to know that email sent successfully? Any kind of acknowledgement or feedback or something??? It is likely to report for any error. Also the file is confidential and is not intended to deviate to some foreign path. Edit: Code being used for mailing. subject="Something happened" to="[email protected]" body="Attachment Test" attachment=/home/iv315/timelog_file_150111.csv (cat test_msg.txt; uuencode $attachment somefile.csv) | mailx -s "$subject" "$to"
Email was designed back when computers did not have a permanent, fast network connection to each other, on the model of postal mail. When you send an email, it gets sent to a server, which sends it to another server, and so on until the email reaches its destination. The oldest mail systems had local delivery, then there were systems where the email had to specify the list of relays until the destination, and nowadays the emails are routed automatically over networks where pretty much all computers can reach each other most of the time. Still, email remains a mail service, not an instant message service. If email is delayed on the way, for example because of a temporary network outage, the intermediate server will keep the email in reserve until the link is restored. Due to this design, email is asynchronous. All the mailx command does is to transmit the email to a local MTA. A return code from mailx indicating success indicates that the local MTA has accepted the job of delivering the email. At that point, the email has been sent successfully. After that, it's the MTA's job to send the email to its destination. If the MTA is unable to make good on its promise to deliver, it is supposed to send a bounce message to the user who sent the email. You cannot know for sure whether the email has been delivered to the recipient's inbox, and even that isn't useful (for example, what if the email is successfully delivered, then the computer where the inbox is stored burns in a fire?). If you need to know whether the recipient received the email, the only sure-fire way is to include human-readable instructions to acknowledge the email. (There are ways to automatically send a receipt when the email is opened in certain software, but they only work in compatible software, and they aren't reliable either, e.g. if the recipient's computer crashed immediately after opening the email.) Knowing whether the email has been delivered doesn't tell you anything about whether other people have been able to read it. Unlike physical objects, electronic messages don't really “deviate”: they are copied, and if there are extra copies around, this cannot be detected. If the email needs to be confidential, encrypt it.
Is there any way to check email sent success acknowledgement?
1,412,767,588,000
(Note: I have seen this question, but it does not work for me) I am attempting to send an email with an attachment using Bash on Debian Stretch, using the mailx package (not mutt). My implementation does not support the -A parameter (it's an invalid option), and the -a parameter is for adding headers. I have tried many variations of the following, but they fail for me: mail -s "Test" -a /home/user/filename.xlsx [email protected] < /root/emailbody.txt The end effect is a plain-text email with the filename as the first line, the header content, then the data inside /root/emailbody.txt: /home/user/filename.xlsx MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Hi there I do not have uuencode, and many threads are reporting that's the "old" way of sending attachments. I cannot install mutt on this server. What are my options? Update with uuencode - I tried running it as the following, but only got "Hi there" as the email result, no attachment: uuencode /home/user/filename.xlsx test.tlsx | mail -s "Test" [email protected] < /root/emailbody.txt
Your original command will work if you have the heirloom-mailx package installed. sudo apt-get install heirloom-mailx Then you can: mailx -s "Test" -a /home/user/filename.xlsx [email protected] < /root/emailbody.txt
Debian mailx won't attach files to emails
1,412,767,588,000
I have a postfix server running on an EC2 instance. I want to forward all email, via SES, to my personal inbox. The problem: AWS only allows a FROM address that is verified in the AWS console and the FROM address in this case could be anything, for example: twitter.com. I cannot white-list my server's IP and say: "Accept all emails from this location regardless of sender" (would be a bad idea anyway) So, I need to figure out a way to forward my email with a verified address but I do not want to lose the original sender's address. Is there a way of doing this?
Based on our discussion in chat, I'm going to provide you my hackish, customized solution that will change the "FROM" address as we expect it to be, and then deliver to the original destination point but add the "Reply-To" header. This is a very hackish approach, but should manipulate the messages as you expect before actually sending them via PostFix to where they need to go. First, PostFix ports need to be changed. We need to change the Postfix SMTP port to something other than 25 so that our python SMTP handler we are going to set up will work on that port instead. Edit /etc/postfix/master.cf. You're going to be looking for a line like this: smtp inet n - y - - smtpd Comment out this line, and underneath that line, use this instead: 10025 inet n - y - - smtpd This tells Postfix that we don't want it to listen on the standard SMTP port. Restart the postfix service when you're done with this step. Next, the Python SMTP handler which I mentioned above. This will handle incoming messages, manipulate them, and resend them to the PostFix on your system. Assuming, of course, that all mail is submitted on port 25, even locally. This code exists on a GitHub GIST and is based off of a generic Python SMTP server code example I got somewhere (but don't remember from where sorry!), and have since manipulated. The code is also here, it's in Python 3 in case you're curious, and is written with Python 3 as the target Python version: #!/usr/bin/env python3 # Libraries import smtplib import smtpd import asyncore import email import sys from datetime import datetime print('Starting custom mail handling server...') # We need to know where the SMTP server is heh. SMTP_OUTBOUND = 'localhost' # We also need to know what we want the "FROM" address to be FROM_ADDR = "[email protected]" DESTINATION_ADDRESS = "[email protected]" ############# ############# # SMTP SERVER ############# ############# # noinspection PyMissingTypeHints,PyBroadException class AutoForwardHandlerSMTP(smtpd.SMTPServer): def process_message(self, peer, mailfrom, rcpttos, data, **kwargs): print('MESSAGE RECEIVED - [%s]' % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) print('Receiving message from:', peer) print('Message addressed from:', mailfrom) print('Message addressed to :', rcpttos) print('Message length :', len(data)) print(data) # Flush the output buffered (handy with the nohup launch) sys.stdout.flush() # Analyze and extract data headers msg = email.message_from_string(data) orig_from = '' try: orig_from = msg['From'] msg['Reply-To'] = orig_from # We have to use 'replace header' methods to overwrite existing headers. msg.replace_header("From", FROM_ADDR) except: print("Error manipulating headers:", sys.exc_info()[0]) conn = smtplib.SMTP(SMTP_OUTBOUND, 10025) conn.sendmail(FROM_ADDR, msg["To"], msg.as_string()) # Flush the output buffered (handy with the nohup launch) print("\n\n") sys.stdout.flush() return # Listen to port 25 ( 0.0.0.0 can be replaced by the ip of your server but that will work with 0.0.0.0 ) server = AutoForwardHandlerSMTP(('0.0.0.0', 25), None) # Wait for incoming emails asyncore.loop() Store this as /opt/PythonAutoForwarderSMTP.py, or whatever you want to call it. Run it with the following as root (either via sudo or by dropping into a root user prompt), first, to make sure it works as we expect: python3 /opt/PythonAutoForwarderSMTP.py Once it's confirmed running, send an email through the server. It should be picked up and give you log data from this script that a message was received and processed. You should also then see a connection on Postfix's logs, and this being delivered somewhere after Postfix. If all of this looks OK, and you process the message properly and see it with a different 'From' address wherever the mail message finally ends up, then we can work to get it to autostart now! (You can simply hit Ctrl + C to close out the python process, before continuing). Assuming we want it to start at boot, then we need to set it up to do so. As root, run crontab -e, and add the following to the root crontab: @reboot /usr/bin/python3 /opt/PythonAutoForwarderSMTP.py 2>&1 >> /var/log/PythonSMTP.log & Save the crontab file. If you don't want to reboot your server, then execute the command line you just added, minus the @reboot part, to run the Python SMTP handler. Whether run by cron or not, the process that loads the Python will end up forked into the background, and also put all data output (error or otherwise in the Python console) to a log file in /var/log/PythonSMTP.log in Append mode. That way, you can always get logs as you need to. If all works as expected, this will properly add a Reply-To header, and also adjust the "From" header in the message to be what we expect it to be. I can't guarantee this'll work properly for SPF and DKIM checking, if messages are signed, but I can say that this will properly 'preprocess' messages before using Postfix to relay them elsewhere. OBLIGATORY Security Concerns and Functional Change Notifications: Sender DKIM verification may fail. DKIM signature verification fails whenever messages that are signed are manipulated, which means you might have broken DKIM signatures from senders. That means things might get picked up as spam due to failed signature verification. This script can probably be customized to 'work' properly, but I didn't write this to do DKIM/SPF checking. We must run this Python SMTP server as root. This is necessary because in Linux by default we can't bind to ports under 1024 unless we are superuser; this is why Postfix has a master 'root' owned process and does sub-processes that don't run as the root user for very long only to port-bind. ALL mail on port 25 will end up going through this Python SMTP server. If Postfix also handles mail from outside->in, then the Python SMTP server will be taking its place. This can introduce some evils, but ultimately does what you're asking for. This is a fragile solution. While it's not as fragile as some other solutions, if the Python process dies, it doesn't come back up automatically, so you have to handle errors on a case-by-case basis and sometimes bring the Python process back to life if it dies off completely. There are no StartTLS or SSL/TLS handlers in this. So everything is Plain Text (which is insecure!) As always, you should not run anything as root unless you know what you're doing. In this case, I provide the code for this in plain view so you can discern for yourself what this script does, and whether you want to run it as root or not, if you are security-centric and paranoid like I am (I am an IT Security professional as well as a sysadmin, so forgive these obligatory notices)
Forward email but change the FROM address
1,412,767,588,000
I have setup a Unix machine with uucp (Unixware) connected via direct serial to Slackware machine. Using uucp. The copy works on Unixware uucp -m /usr/bin/view Slackware1\!/var/spool/uucppublic mailx .... ..... Content-Type: text/plain; charset=us-ascii Status: R Content-Length: 121 REQUEST: unixware2!/usr/bin/view --> Slackware1!/var/spool/uucppublic (myusername) (SYSTEM: Slackware1) copy succeeded Now we try the mailx on remote and.. echo something|uux -z Slackware1\!/usr/bin/mailx myuser On Slackware server the uucp log said.. ERROR: Not permitted to execute /usr/bin/mailx Of course the mail don't arrive. Those are the permission configuration On Linux /etc/uucp/sys remote-send ~ remote-receive ~ local-send ~ local-receive ~ command-path /usr/bin commands ls mailx system unixware2 time any port serial1 speed 38400 chat in:--in: nuucp word: *** on unixware /etc/uucp/Permissions LOGNAME=nuucp \ MACHINE=OTHER \ READ=/var/spool/uucppublic \ WRITE=/var/spool/uucppublic \ SENDFILES=call REQUEST=yes \ COMMANDS=/usr/bin/rmail:/usr/bin/mailx \ PUBDIR=/var/spool/uucppublic \ MYNAME=unixware2 \ VALIDATE=Slackware1 LOGNAME=myusername \ MACHINE=OTHER \ READ=/var/spool/uucppublic \ WRITE=/var/spool/uucppublic \ SENDFILES=call REQUEST=yes \ COMMANDS=/usr/bin/rmail:/usr/bin/mailx \ PUBDIR=/var/spool/uucppublic \ MYNAME=unixware2 \ VALIDATE=Slackware1 any suggestion?Thanks edit1: Trying uux -a nuucp.. make the same error
Solution found on /etc/uucp/sys instead of commands mailx we use commands /usr/bin/mailx Works fine. The command for sent email using mailx is this uux - -z Slackware1\!/usr/bin/mailx -s subject myuser or in one line echo -e 'Hello, A message for you\nhow are you...blablabla' | uux - 'Slackware1!mailx myuser'
Uucp: copy...but not command execution allowed
1,412,767,588,000
I've come across different names in different places: Light MTA, Remote MTA, Smarthost, etc. Generally, I do not want to install a full-fledged mail server (such as sendmail, postfix, exim), but only send notifications/emails using an existing external ISP/mail provider (such as dismail.de, mailfence.com or others) with unattended-upgrades, cron, smartmontools, my own bash scripts etc from all over the system. Additionally, it would be ideal if there was support for queuing and retrying (an attempt to resend in the event of being offline or temporarily unreachable by the mail provider) So far I've found: ssmtp msmtp s-nail nullmailer dma esmtp But I didn't find any comparison between them. Does anyone know what makes the program stand out from the rest? (positives, negatives, ease of configuration, low resource consumption, etc.) Possibly I missed something and maybe there is another one, better than all those mentioned for Debian? Did I understand correctly that s-nail is also an MUA and bsd-mailx or mailutils is not needed? Maybe others too?
After conducting my research: From the list given above, message queuing and retrying (for example when the laptop was temporarily offline or the mail server was temporarily down) only support: msmtp nullmailer dma msmtp: I rejected msmtp because queuing is not supported natively and requires a workaround through additional overlays: https://wiki.archlinux.org/title/Msmtp#Using_msmtp_offline https://gitlab.com/the-foundation/msmtp-cron-sendmail nullmailer: nullmailer seemed fine at first, but: the documentation is virtually non-existent the configuration options are scattered across individual files and do not work as intuitively as their names suggest The biggest problem turned out to be the allmailfrom option, which simply doesn't work: many email providers reject emails containing user@host of the local machine instead of the real email address in other cases, such emails often end up in spam the issue has been reported and has not been fixed since April 2020 https://github.com/bruceg/nullmailer/issues/72 there is a workaround, but personally I am not interested in tricks and workarounds because I am looking for a solution that is elegant and works out of the box https://www.atwillys.de/content/linux/force-nullmailer-to-use-a-fixed-from-address/ dma: For me the winner is DMA (DragonFly Mail Agent): configuration works perfectly and took 3 minutes the configuration consists of only two files /etc/dma/dma.conf and /etc/dma/auth.conf which are intuitive and have option descriptions to solve the problem of the from field from nullmailer, just [email protected] in the dma.conf file and everything works like a charm all system notifications work correctly (Unattended-Upgrades, Cron, Timeshift, scripts, etc.) it is light, fast and safe (I would like to remind you that it is only used to send e-mails and does not receive e-mails, but many people want this) Additional information: https://askubuntu.com/questions/759665/how-to-configure-nullmailer-to-work-with-gmx/759682#759682 https://wiki.mageia.org/en/Dma_Dragonfly_Mail_Agent https://wiki.archlinux.org/title/Dma Tested on Debian 11 and LMDE 5
Light program (mini MTA?) for system mail (only sending/relay via external server with unattended-upgrades, cron, smartmontools, etc.)
1,412,767,588,000
I have a cron job which runs a long script producing lots of output. Some of the output is lines delimited by single carriage returns; when run from the command line, these make the successive lines overwrite each other, providing progress output without overly polluting the backscroll. However, when looking at the output from the cron job, I want to see all these lines without missing any. Until recently, when I used mailx to print the output reports from the cronjob, it would replace the control characters with reverse-video ^M to highlight them. This was the behavior I wanted, as it left all of the lines visible. Now, however, something unknown has changed (a version upgrade?), and mailx prints the control characters as-is, causing them to overwrite each other when mail is printed. How can I reverse this behavior and make mailx replace control characters again?
It turned out that the issue lay with mailx's pager setting. It began using more for some reason, when previously it had used less (which does the escaping). Linking more to less again restored the old behavior.
Control character handling in cron/mailx
1,412,767,588,000
I'm trying to setup mailx to use my Gmail account. I've found a configuration that can send mail successfully but it requires me to store my email password in a configuration file in my home directory. I would like to be prompted for the password every time rather than storing it. I've tried leaving out the smtp-auth-password field where the password is present but the program does not prompt for a password and instead gives me this error: User and password are necessary for SMTP authentication. Is there any way configure mailx such that my email password is used in a secure manner? Here is my mailx config file: account gmail { set folder=imap://(removed)@imap.gmail.com set smtp-use-starttls set ssl-verify=ignore set smtp=smtp://smtp.gmail.com:587 set smtp-auth=login set from=(removed)@gmail.com set smtp-auth-user=(removed) set smtp-auth-password=(removed) set nns-config-dir=~/.certs }
Which version of mailx are you using? heirloom-mailx 12.5 on Ubuntu 14.04 prompts me for the password every time if there's no smtp-auth-password setting in ~/.mailrc. This feature was added in 12.0 in March 2006 according to ChangeLog.
Using mailx without storing a password
1,412,767,588,000
I just set up a VPS with Debian 7 x64, and removed Sendmail along with some other programs. When it removed Sendmail, it also installed Exim. When I removed Exim, it installed xmail. Is there any reason why it seems to require a mail program? I used apt-get remove --purge sendmail* exim* to remove them
One of your installed packages depends on installed MTA. This is most likely cron. You can view why a package (or meta package) is installed with aptitude: aptitude why mail-transport-agent
Why does uninstalling sendmail install exim, and uninstalling exim installs xmail?
1,412,767,588,000
I want to install heirloom-mailx on Ubuntu 14.04 My current /etc/apt/sources.list reads like this: deb http://archive.ubuntu.com/ubuntu/ trusty main restricted deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted And apt-get is unable to find heirloom-mailx with this sources.list What changes do I need to find heirloom-mailx?
You should have the following line in your sources.list: deb http://security.ubuntu.com/ubuntu trusty-security main universe Then run: sudo apt-get update sudo apt-get install heirloom-mailx
How to install heirloom-mailx on Ubuntu 14.04
1,485,760,371,000
If postfix is setup as the MTA using its virtual transport to deliver mail to a local mbox file (and handling delivery of outgoing messages), and mailx is the MUA, being used on that same computer for reading and composing messages, can only one of these operations happen at once due to mbox file locking? If a user is using mailx to read their messages and perhaps reply to or compose a few messages, does this prevent postfix from delivering new messages to the user's mbox file? Does this create a situation where the user might not receive some messages due to the incoming messages being bounced? What is the process for mbox file locking here? When and where is it happening? I am trying to get a better idea of how this works.
You are right, Postfix will lock the mail file during delivery. The mailbox is locked for exclusive access while delivery is in progress. Read more about it here But that doesnt mean that your other incoming mails will bounce. If postfix cant deliver during a try, Apr 15 14:02:25 server.tld postfix/local[67533]: D8C46C9014D: to=, relay=local, delay=1956, delays=1936/0.01/0/20, dsn=4.2.0, status=deferred (cannot update mailbox /var/spool/mail/user for user user. unable to create lock file /var/spool/mail/user.lock: File exists) it will keep your mail in deferred queue and retry it later until maximal_queue_lifetime expires. The default maximal_queue_lifetime value is 5 days
How do postfix and mailx interact with mbox locking?
1,485,760,371,000
Problem Statement:- Currently I am sending an email using mailx by attaching an html file within the email. But I want to send an email using mailx command instead of attaching the html file in an email, I want to show the results of html file within an email body. Below is the script I am using to send an email with some content in the body of an email and attaching chart.html file in an email. And instead of attaching html file in an email, I want to show the output of html file within an email body. Can anyone show me an example basis on my below script what changes I need to make to accomplish this? mailx -s "LIP for $DATE_YEST_FORMAT1" -r [email protected] [email protected] <<EOF Total Items Purchased: `echo $QUERY1 | awk '{print $1}'` Total Items Missingo: `echo $QUERY1 | awk '{print $2}'` Error Percentage: $QUERY2 `uuencode /tmp/chart.html chart.html` EOF And this is my chart.html file which draws a graph- So I need to show this graph within the email body. <html> <head> <!--Load the AJAX API--> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> // Load the Visualization API and the piechart package. google.load('visualization', '1.0', {'packages':['corechart']}); // Set a callback to run when the Google Visualization API is loaded. google.setOnLoadCallback(drawChart); // Callback that creates and populates a data table, // instantiates the pie chart, passes in the data and // draws it. function drawChart() { // Create the data table. var data = new google.visualization.DataTable(); data.addColumn('string', 'Title'); data.addColumn('number', 'Value'); data.addRows([ ['No Error Percentage', $NOERROR], ['Error Percentage', $ERROR] ]); // Set chart options var options = {'title':'LIP Data Quality Report', 'width':700, 'height':600}; // Instantiate and draw our chart, passing in some options. var chart = new google.visualization.PieChart(document.getElementById('chart_div')); chart.draw(data, options); } </script> </head> <body> <!--Div that will hold the pie chart--> <div id="chart_div" style="width:900px; height: 800px;"></div> </body> </html> Any help will be appreciated. And I am running SunOS bash-3.00$ uname -a SunOS lvsaishdc3in0001 5.10 Generic_142901-02 i86pc i386 i86pc
You cannot do that with text/plain email. To directly embed that html into the email message will only work if the receiving email client software supports JavaScript. I am not aware of any that do. You basically have two options. The first is to have graphing software produce an image file that can be embedded in an HTML email. This image will be presented in the email at the location it is embedded. The second is to include a link in an HTML email that will present the graph. This will probably require a browser to be opened to get the actual content. With the first option, you would have to build the email message using Content-Type: multipart/related type="multipart/alternative", including at least two parts, the first of type text/html and the second of type image/<whatevertypeyourimageis>. See the "Including Images" section on this page for more information on how to do it. With the second option, there are two different approaches. The first is to put up a generic page that accepts data encoded in the URL and renders the page accordingly. The second is to put up a unique page for each data set.
Send the Output of an HTML file within the email body using mailx
1,485,760,371,000
new person here. I would like to run uptime and bdf and have the output emailed to me. I have the mailx part down- /usr/bin/mailx -s "daily_update" [email protected] </home/daily_update And I am ok with how to add it to the cron so it sends the email everyday at 8:00am. Just not sure how to do the scripting part that captures the output of uptime and bdf? Thank you
cron sends email with any command output by default, either to the user specified by MAILTO, or to the owner (which requires local email delivery to work). A crontab such as this should do the trick, no need to handle email specially: [email protected] 0 8 * * * uptime 0 8 * * * bdf
How to run a few commands and have the output emailed once a day?
1,485,760,371,000
Currently I have file with structure as Foo Sign: blah SubFoo Sign: blah BarDate: 2017-11-31 Foo Sign: blah BarDate: Never Foo Sign: blah BarDate: 2016-12-20 Foo Sign: blah BarDate: 2014-12-20 .... and so on This are the main four categories of data which resides in the file. Don't go with the foo,bar,blah things, those are not important. Main important thing is BarDate and its value. Main Part Case 1: If BarDate value is Never I don't have to do anything. Case 2: If BarDate has some value other than Never it has the format as YYYY-MM-DD. Requirement: If the BarDate is within the span of 10 days from today it will mail to someone with it's details. So, today is 15-12-2015 if there is any BarDate which is within 15th to 25th December of 2015 a mail will be send with it's Foo Sign,BarDate. So a mail will be triggered for 2015-12-16,2015-12-24,2015-12-25... But not for 2014-12-16,2016-12-24,2015-12-26 So far my shell script is foo="" bardate="" outputfile="test.txt" result="" newline="\n" ### just a workaround step ### if [ -f $outputfile ]; then `rm $outputfile` fi ### filtering the date which doesn't have BarDate as Never, and writing it to a file ### `cat datafile | grep -e "Foo Sign" -e BarDate | grep -v "Never" | uniq >> $outputfile` IFS=$'\n' ### contains is a custom function which returns 1 if param1 is substring of param2 ### for line in ${cat outputfile}; do contains "$line" "Foo Sign" && foo="$line" ### constructing the result string ### ### -----> here I have to extract the date and see if it resides within 10 days span from today <----- ### ### then only the result string will be constructed ### contains "$line" "BarDate" && bardate="$line" && result=$result$newline$foo$newline$bardate$newline done ### mail the result ### echo -e "$result" | mailx -s "BLAH" [email protected]
You can get current epoch time with date "+%s" You can also convert any time format to epoch time: date -d "${MY_TIME}" "+%s" And these epoch times you can substract. Having the line with BarDate: 2017-11-31 in a variable LINE, you can extract the date using: MY_TIME=$(echo $LINE | cut -d: -f2)
How to extract date and calculate if it is within "x" days from today?
1,485,760,371,000
How can I check with bash or python (preferred) if there are some unread mails in /var/spool/mail/$USER like pam_mail does? I'd like to use this for my own custom motd script, motd.dynamic
The way to determine whether there are unread mails in a mailbox file is traditionally to check if the access time is earlier than the modification time. You can easily find these times using the stat command; by specifying a custom output format these values can be imported into the shell: eval $(stat -c 'atime=%X; mtime=%Y' /var/spool/mail/$USER) After that you can compare these values: if [ $atime -le $mtime ]; then echo 'You have new mail'; fi To make it a bit more robust, check the existence of the mail file first.
check "newness" / "is-read" of /var/spool/mail/$USER like pam_mail for custom motd script
1,485,760,371,000
I've installed mailx, and when I try to send an email, like: echo "Test" | mailx -r "[email protected]" -s "Test" "[email protected]" It executes. But I don't receive the email. How do I set mailx up to send to Gmail, while retaining the ability to customize the sender ID?
You can't do this without some form of authentication that you are the correct user. https://en.wikipedia.org/wiki/Email_spoofing This used to be a big problem, before people fixed it with cryptographic signatures. You could receive an email from a criminal, pretending to be your boss, asking you to send them the secret project of the future. If you host your own mail server, you will be able to customise the username, but you will either need to have some way of keeping your IP constant (or replies will not work), or DDNS. EDIT: as @tripleee mentioned, this has to be set up as SMTP settings, this is not a mailx problem
Using Mailx with Gmail
1,485,760,371,000
I have 2 Linux CentOS 7 machines, a Samba server and a Postfix server. The Postfix server is configured to use SASL authentication and TLS encryption. On the Samba server, I can connect to the Postfix server using openssl. [root@samba1 ~]# openssl s_client -connect mail.example.com:587 -starttls smtp -CAfile /etc/pki/tls/mail.example.com.pem When I use mailx on the Samba server, I get message "SSL/TLS handshake failed: Unknown error -5938". [root@samba1 ~]@ echo "Hello World" | mailx -v -s "Test" -A default [email protected] Resolving host mail.example.com . . . done. Connecting to 192.168.0.10:587 . . . connected. SSL/TLS handshake failed: Unknown error -5938. In /var/log/maillog on the Postfix server, I do see a few TLS events. Nov 25 19:23:05 mail postfix/smtpd[5659]: initializing the server-side TLS engine Nov 25 19:23:05 mail postfix/smtpd[5659]: connect from samba1.example.com[192.168.0.12] Nov 25 19:28:05 mail postfix/smtpd[5659]: timeout after UNKNOWN from samba1.example.com[192.168.0.12] This is my /etc/mail.rc file on the Samba server. [root@samba1 ~]# cat /etc/mail.rc account default { set smtp=smtps://mail.example.com:587 #Authentication set smtp-auth=login set [email protected] set smtp-auth-password="my_password" #Encryption set smtp-use-starttls set nss-config-dir=/etc/pki/nssdb } set hold set append set ask set crt set dot set keep set emptybox set indentprefix="> " set quote set sendcharsets=iso-8859-1,utf-8 set showname set showto set newmail=nopoll set autocollapse set markanswered ignore received in-reply-to message-id references ignore mime-version content-transfer-encoding fwdretain subject date from to set bsdcompat This article suggests to comment out smtp-use-starttls, which seems to not apply to my situation, since my Postfix server is configured to use TLS. If I comment out smtp-use-starttls, I stil get the 5938 message. This post suggests that you can ensure both servers are using the same version of TLS. I added ssl-method=tls1 to /etc/mail.rc on the Samba server, and I still get the 5938 message. Using certutil, I do see my certificate in /etc/pki/nssdb on the Samba server, and it is valid. [root@samba1 ~]# certutil -V -n "mail.example.com.crt" -d /etc/pki/nssdb -u A certutil: certificate is valid Here is the contents of nssdb -rw-r--r--. 1 root root 65536 Nov 25 17:56 cert8.db -rw-r--r--. 1 root root 9216 Jun 26 08:51 cert9.db -rw-r--r--. 1 root root 16384 Nov 25 17:56 key3.db -rw-r--r--. 1 root root 11264 Jun 26 08:51 key4.db -rw-r--r--. 1 root root 451 Apr 25 2016 pkcs11.txt -rw-r--r--. 1 root root 16384 Apr 25 2016 secmod.db I am not certain what I should do next for this anomaly.
dave_thompson_085 answered in the comments: smtps: means to initially connect with SSL/TLS, which 587 does not support. You want to connect then start SSL/TLS, which is generically called starttls. Use: smtp=server:587 and smtp-use-starttls
Mailx SSL/TLS handshake failed: Unknown error -5938
1,485,760,371,000
save internal variable enable saving of messages in the dead.letter file on interrupt or delivery error.The default is save. problem: default is save so dead.letter file is created at home directory, expected: I want to change the value of save variable so file will not be generated I tried set save=false;, but its not working
The man page for my mailx says a lot of things about set nosave and so on, but they dont seem to work. The only way to stop your dead.letter file growing I have found is to replace it by a link to the special file /dev/null. rm ~/dead.letter ln -s /dev/null ~/dead.letter
how to set Internal Variables in mailx in linux?
1,485,760,371,000
I am sending multiple files using following line in my script find . -type f -name "Sum*pdf*"|while read name; do uuencode "$name" "${name##*/}"; done | mailx -s "North Bus Correction" $RECIP Now I want to have body of mail as well with the attachments and I have tried the below one (echo "Bus Correction";find . -type f -name "Sum*pdf*"|while read name; do uuencode "$name" "${name##*/}"; done) | mailx -s "North Bus Correction" $RECIP But I am getting only attachments not with body of mail. What is wrong in that please help me on this. I am using AIX.
Wow.... My trails were worked (echo "Bus Correction" && find . -type f -name "Sum*pdf*"|while read name; do uuencode "$name" "${name##*/}"; done)| mailx -s "North Bus Correction" $RECIP
Mailx with multiple uuencode attachments and body
1,485,760,371,000
I have exim installed and configured as "internet site; mail is sent and received directly using SMTP". Mail is stored in /home/*user*/Maildir and it is really there. I can send and receive mail globally and internally, but my Debian Wheezy's mail program isn't showing any of it. Does mail support Maildir format at all? The messages are there, I can access them via mutt -f Maildir. It's convenient to see a number of new e-mails at SSH logon.
Okay, @jordanm gave me a right direction, but information is scattered across the Net, so I think it is worth to post some kind of guide myself. Install mailutils and heirloom-mailx packages: sudo apt-get install mailutils heirloom-mailx Update alternatives for mailx — choose /usr/bin/heirloom-mailx: sudo update-alternatives --config mailx The last part: update 3 files in /etc/pam.d/. There is a string in each of three following files, which starts with session optional pam_mail.so, update it with the following values: /etc/pam.d/login: session optional pam_mail.so dir=~/Maildir standard /etc/pam.d/su: session optional pam_mail.so dir=~/Maildir nopen /etc/pam.d/sshd: session optional pam_mail.so dir=~/Maildir standard Sources: Ask Ubuntu and this blog post.
Debian: exim, Maildir and mail
1,485,760,371,000
Unable to send out emails from my Linux Host. Below is the command I try: echo "This is the message body and contains the message" | sudo mailx -v [email protected] -s "This is the subject" or mail -s "Test Subject" [email protected] < /home/system/mailbody.txt Output: Mail Delivery Status Report will be mailed to <root>. Here is the Running process. $ ps -ef | grep postfix postfix 2993 30866 0 19:15 ? 00:00:00 pickup -l -t unix -u system 4399 594 0 19:28 pts/0 00:00:00 grep --color=auto postfix root 30866 1 0 2020 ? 00:00:19 /usr/libexec/postfix/master -w postfix 30868 30866 0 2020 ? 00:00:05 qmgr -l -t unix -u Here is the telnet showing port 25 is LISTENING on my system: $ telnet localhost 25 Trying ::1... Connected to localhost. Escape character is '^]'. 220 efendibey_live.localdomain ESMTP Postfix Here is the output of mailq: $ mailq -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient------- AE3BF1FC5 606 Sun Feb 7 19:15:10 system@efendibey_live.localdomain (connect to mx2.zoho.com[136.143.191.44]:25: Connection timed out) [email protected] 7410B47CA 602 Sun Feb 7 19:18:57 system@efendibey_live.localdomain (delivery temporarily suspended: connect to alt2.gmail-smtp-in.l.google.com[2404:6800:4003:c06::1a]:25: Network is unreachable) [email protected] 3EC5F1EC2 474 Sun Feb 7 19:13:34 system@efendibey_live.localdomain (connect to mx2.zoho.com[136.143.191.44]:25: Connection timed out) [email protected] 456251FC6 656 Sun Feb 7 19:18:04 system@efendibey_live.localdomain (connect to mx2.zoho.com[136.143.191.44]:25: Connection timed out) [email protected] 1CB9D48FB 652 Sun Feb 7 19:20:04 system@efendibey_live.localdomain (connect to alt2.gmail-smtp-in.l.google.com[2404:6800:4003:c06::1a]:25: Network is unreachable) [email protected] 1FE9B450F 652 Sun Feb 7 19:19:45 system@efendibey_live.localdomain (connect to alt2.gmail-smtp-in.l.google.com[2404:6800:4003:c06::1a]:25: Network is unreachable) [email protected] B180025B5 654 Sun Feb 7 19:25:25 root@efendibey_live.localdomain (delivery temporarily suspended: connect to alt2.gmail-smtp-in.l.google.com[2404:6800:4003:c06::1a]:25: Network is unreachable) [email protected] Update: The outbound port is also open and connecting: $ telnet gmail-smtp-in.l.google.com 25 Trying 108.177.119.26... Connected to gmail-smtp-in.l.google.com. Escape character is '^]'. 220 mx.google.com ESMTP g24si11485107edh.82 - gsmtp Once I fire the command to sent out an email I can see it in the mailQ and then disappear from the Queue, however, I still do not receive the mail in my inbox. [system@efendibey_live ~]$ echo "This is the message body and contains the message" | sudo mailx -v [email protected] -s "This is the subject" Mail Delivery Status Report will be mailed to <root>. [system@live ~]$ mailq -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient------- 3723C16BC* 658 Mon Feb 8 13:37:13 root@ebey_live.localdomain [email protected] -- 1 Kbytes in 1 Request. [system@live ~]$ mailq Mail queue is empty [system@live ~]$ The below is the output from tail -f /var/log/maillog for a single mail send command. Feb 8 15:29:43 Efendibey_Live postfix/pickup[10591]: E4F5F16A9: uid=0 from=<root> Feb 8 15:29:43 Efendibey_Live postfix/cleanup[18223]: E4F5F16A9: message-id=<20210208152943.E4F5F16A9@efendibey_live.localdomain> Feb 8 15:29:43 Efendibey_Live postfix/qmgr[1193]: E4F5F16A9: from=<root@efendibey_live.localdomain>, size=467, nrcpt=1 (queue active) Feb 8 15:29:45 Efendibey_Live postfix/smtp[18225]: E4F5F16A9: to=<[email protected]>, relay=mx.zoho.com[136.143.191.44]:25, delay=1.2, delays=0.03/0.01/0.67/0.51, dsn=5.7.1, status=bounced (host mx.zoho.com[136.143.191.44] said: 541 5.7.1 Mail rejected due to antispam policy (in reply to RCPT TO command)) Feb 8 15:29:45 Efendibey_Live postfix/cleanup[18223]: 468D216BC: message-id=<20210208152945.468D216BC@efendibey_live.localdomain> Feb 8 15:29:45 Efendibey_Live postfix/qmgr[1193]: 468D216BC: from=<>, size=2472, nrcpt=1 (queue active) Feb 8 15:29:45 Efendibey_Live postfix/bounce[18227]: E4F5F16A9: sender non-delivery notification: 468D216BC Feb 8 15:29:45 Efendibey_Live postfix/qmgr[1193]: E4F5F16A9: removed Feb 8 15:29:45 Efendibey_Live postfix/local[18228]: 468D216BC: to=<root@efendibey_live.localdomain>, relay=local, delay=0.02, delays=0.01/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox) Feb 8 15:29:45 Efendibey_Live postfix/qmgr[1193]: 468D216BC: removed I even tried the -f [email protected] option in mailx but still, no emails received. Here is my /etc/hosts entry # cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 127.0.0.1 guest ::1 guest 127.0.0.1 Efendibey_Live ::1 Efendibey_Live Can you please suggest how can I get emails to work from my Linux host?
In an update you showed your /var/log/mail.log contained this: Feb 8 15:29:43 Efendibey_Live postfix/qmgr[1193]: E4F5F16A9: from=<root@efendibey_live.localdomain>, size=467, nrcpt=1 (queue active) Feb 8 15:29:45 Efendibey_Live postfix/smtp[18225]: E4F5F16A9: to=<[email protected]>, relay=mx.zoho.com[136.143.191.44]:25, delay=1.2, delays=0.03/0.01/0.67/0.51, dsn=5.7.1, status=bounced (host mx.zoho.com[136.143.191.44] said: 541 5.7.1 Mail rejected due to antispam policy (in reply to RCPT TO command)) This means your message was sent successfully, but it was rejected by the recipient. What's also interesting is the from= address. It looks like your domain is efendibey_live.localdomain. If the recipient can't do a DNS lookup of your domain, then they will often reject your email. When postfix is configured, it uses the output of hostname -f to set everything up. That's a function of your machine name, and of the DNS entry for your machine. The solution is to update your /etc/postfix/main.cf. My stuff looks like this: $ hostname -f mail.example.com $ cat /etc/hostname mail.example.com $ host -t mx example.com example.com is handled by 10 MAIL.example.com $ host -t a mail.example.com mail.example.com has address aa.bb.cc.dd $ cat /etc/postfix/main.cf | grep myhostname smtpd_banner = $myhostname ESMTP $mail_name myhostname = example.com mydestination = $myhostname, example.com, mail.example.com, localhost.example.com, localhost
Unable to send out emails from my Linux Host
1,485,760,371,000
I was trying to send a mail from the shell script using the command mailx -s "TEST MAIL" -c "user_name ..." user<message.txt but it generates an error as unrecognized option -c ,the same happens if i use -b as a option for blind copy, so what options do i need to use for cc and bcc here ???
Debian and Ubuntu have replaced Heirloom mailx with s-nail mailx. Both support the -b and -c options. But there are other mailx commands from other packages which do not. I suspect that you, too, are unknowingly using the GNU Mailutils mailx or the NMH mailx. The latter re-spells the -c option as -cc but has no equivalent for -b. The former has no direct equivalents for either, requiring that headers be injected using a generic mechanism. (Note that, strictly speaking, -b and -c control envelope not headers, although the distinction between them is blurry at the level of mailx.) Further reading mailx. Ubuntu 16.04 manual pages. mailx. Ubuntu 16.04 manual pages. mailx. Ubuntu 16.04 manual pages. mailx. Ubuntu 14.04 manual pages. s-nail. User commands. s-nail. Debian manual pages. mailx. User commands. GNU mail utils. Debian manual pages. mailx. General Commands Manual. BSD mailx. Debian manual pages. mailx. User commands. NMH. Debian manual pages. Difference between mail and mailx? https://unix.stackexchange.com/a/469833/5132
-c and -b options not working in mailx in ubuntu
1,485,760,371,000
In Heirloom mailx, one can specify "from address" (-r) and "reply-to address" (-R). What is the difference between the two?
From RFC 2822 para 3.6.2: When the "Reply-To:" field is present, it indicates the mailbox(es) to which the author of the message suggests that replies be sent. In the absence of the "Reply-To:" field, replies SHOULD by default be sent to the mailbox(es) specified in the "From:" field unless otherwise specified by the person composing the reply. You can compose and send an email (from you) and have the reply sent to some other mailbox (your secretary maybe) or a group mailbox.
Difference between Reply-To address and From address in an email