Let $d$ be a natural number. Given two natural numbers $M$ and $N$ with $d$ digits, $M$ is a friend of $N$ if and only if the $d$ numbers obtained substituting each one of the digits of $M$ by the digit of $N$ which is on the same position are all multiples of $7$. Find all the values of $d$ for which the following condition is valid:
For any two numbers $M$ and $N$ with $d$ digits, $M$ is a friend of $N$ if and only if $N$ is a friend of $M$.
1. **Define the problem and notation:**
   Let \( d \) be a natural number. Given two natural numbers \( M \) and \( N \) with \( d \) digits, \( M \) is a friend of \( N \) if and only if the \( d \) numbers obtained by substituting each one of the digits of \( M \) by the digit of \( N \) which is in the same position are all multiples of \( 7 \). We need to find all values of \( d \) for which the following condition is valid: For any two numbers \( M \) and \( N \) with \( d \) digits, \( M \) is a friend of \( N \) if and only if \( N \) is a friend of \( M \).

2. **Express \( M \) and \( N \) in terms of their digits:**
   Let \( M = \sum_{k=0}^{d-1} m_k 10^k \) and \( N = \sum_{k=0}^{d-1} n_k 10^k \).

3. **Condition for \( M \) to be a friend of \( N \):**
   The statement that \( M \) is a friend of \( N \) is equivalent to:
   \[
   M + 10^k (n_k - m_k) \equiv 0 \pmod{7} \quad \text{for all } 0 \leq k \leq d-1.
   \]

4. **Case 1: \( d \not\equiv 2 \pmod{7} \):**
   - Assume \( M \) is a friend of \( N \) and vice versa.
   - Summing all the equalities, we get:
     \[
     dM + N - M \equiv 0 \pmod{7} \quad \text{and} \quad dN + M - N \equiv 0 \pmod{7}.
     \]
   - Subtracting these two congruences:
     \[
     (d-2)M \equiv (d-2)N \pmod{7} \implies M \equiv N \pmod{7}.
     \]
   - Since \( M \) and \( N \) are congruent modulo 7, we can write:
     \[
     M + 10^k (n_k - m_k) \equiv 0 \equiv N + 10^k (m_k - n_k) \equiv M + 10^k (m_k - n_k) \pmod{7}.
     \]
   - This implies \( M \equiv N \equiv 0 \pmod{7} \).
   - However, there exist numbers \( M \) and \( N \) such that \( M \) is a friend of \( N \) and \( 7 \nmid M \). For example, take \( M = 10^{d-1} \), \( n_{d-1} = 7 \), and \( n_k \equiv -10^{d-k} \pmod{7} \). If \( k < d-1 \), then:
     \[
     M + 10^k (n_k - m_k) = 10^d + 10^k n_k \equiv 0 \pmod{7},
     \]
     and if \( k = d-1 \), then:
     \[
     M + 10^k (n_k - m_k) = 7 \times 10^{d-1} \equiv 0 \pmod{7}.
     \]
   - This shows that \( N \) is not necessarily a friend of \( M \), contradicting the condition.

5. **Case 2: \( d \equiv 2 \pmod{7} \):**
   - Assume \( M \) is a friend of \( N \).
   - Summing the equalities \( M + 10^k (n_k - m_k) \equiv 0 \pmod{7} \), we get:
     \[
     dM + N - M \equiv 0 \pmod{7} \implies 2M + N - M \equiv M + N \pmod{7} \quad \text{(since \( d \equiv 2 \pmod{7} \))}.
     \]
   - This implies:
     \[
     N + 10^k (m_k - n_k) \equiv -M - 10^k (n_k - m_k) \equiv 0 \pmod{7},
     \]
     so \( N \) is a friend of \( M \), as desired.

6. **Conclusion:**
   The only values of \( d \) for which the condition is valid are those such that \( d \equiv 2 \pmod{7} \).

The final answer is \( \boxed{ d \equiv 2 \pmod{7} } \).